Android 中的错误 -- 无法找到以下项的检测信息:ComponentInfo

发布于 2024-12-07 09:24:21 字数 1578 浏览 1 评论 0原文

例如,我有一个应用程序将调用联系人并且必须选择其中一个联系人。 但它并没有完全按照我想要的方式做。它向我显示错误无法找到仪器信息:ComponentInfo{com.sample/com.sample.ContactsSelectInstrumentation}

以下是我的代码.. 这是我的活动课

 @Override  
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.go);
button.setOnClickListener(mGoListener);
}
private OnClickListener mGoListener = new OnClickListener() {
public void onClick(View v) {
  startInstrumentation(new ComponentName(Test.this,
      ContactsFilterInstrumentation.class), null, null);
}
};

这是我的仪器课。

class ContactsFilterInstrumentation extends Instrumentation {  
@Override    
  public void onCreate(Bundle arguments) {

super.onCreate(arguments);
start(); 

} 

 @Override  

public void onStart() {

super.onStart();

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(getTargetContext(), "com.android.phone.Dialer");
Activity activity = startActivitySync(intent);

Log.i("ContactsFilterInstrumentation", "Started: " + activity);
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_M));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_M));
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A));
waitForIdleSync();
Log.i("ContactsFilterInstrumentation", "Done!");
finish(Activity.RESULT_OK, null);
}
}

任何人都可以帮助我吗? 提前致谢。

For Example I had an application that will invoke contacts and has to select one of the contact.
But its not doing exactly what I want. It is showing me error Unable to find instrumentation info for: ComponentInfo{com.sample/com.sample.ContactsSelectInstrumentation}

Following is my Code..
This is my Activity class

 @Override  
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.go);
button.setOnClickListener(mGoListener);
}
private OnClickListener mGoListener = new OnClickListener() {
public void onClick(View v) {
  startInstrumentation(new ComponentName(Test.this,
      ContactsFilterInstrumentation.class), null, null);
}
};

And this is my Intrumentation class.

class ContactsFilterInstrumentation extends Instrumentation {  
@Override    
  public void onCreate(Bundle arguments) {

super.onCreate(arguments);
start(); 

} 

 @Override  

public void onStart() {

super.onStart();

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(getTargetContext(), "com.android.phone.Dialer");
Activity activity = startActivitySync(intent);

Log.i("ContactsFilterInstrumentation", "Started: " + activity);
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_M));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_M));
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A));
waitForIdleSync();
Log.i("ContactsFilterInstrumentation", "Done!");
finish(Activity.RESULT_OK, null);
}
}

Can Any help me out.
Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

高速公鹿 2024-12-14 09:24:21

目录结构应该是:

src
  package.x.y.z.test
      MainTest.java
      CustomInstrumentationRunner.java

然后在AndroidManifest.xml中,设置

<manifest package="package.x.y.z" ...

<instrumentation
        android:name="package.x.y.z.test.CustomInstrumentationRunner"

用命令行调用上面的包:

adb shell am instrumentation -w package.x.y.z/package.x.y.z.test.CustomInstrumentationRunner

Directory structure should be:

src
  package.x.y.z.test
      MainTest.java
      CustomInstrumentationRunner.java

Then in the AndroidManifest.xml, set

<manifest package="package.x.y.z" ...

<instrumentation
        android:name="package.x.y.z.test.CustomInstrumentationRunner"

Invoke the above package with the command line:

adb shell am instrumentation -w package.x.y.z/package.x.y.z.test.CustomInstrumentationRunner
酒浓于脸红 2024-12-14 09:24:21

通过 AndroidManifest.xml 的 标签向系统描述 Instrumentation 实现。

An Instrumentation implementation is described to the system through an AndroidManifest.xml's <instrumentation> tag.

海之角 2024-12-14 09:24:21

我通过执行以下操作解决了这个问题:

  1. 在清单中使用上层包名称:

  2. 向下一级实施测试包:
    Java文件1:

    package com.xxx.yyy.zzz.ptest.onlylogin;

Java 文件 2:

package com.xxx.yyy.zzz.ptest.register;
  1. 指定如下命令行:

    ...

I solved this problem by doing the following:

  1. Use a upper-level package name in the manifest:

  2. Implement the test packages one level down:
    Java file 1:

    package com.xxx.yyy.zzz.ptest.onlylogin;

Java file 2:

package com.xxx.yyy.zzz.ptest.register;
  1. Specify the command line like the following:

    ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文