Android - 未找到活动异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3533370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:38:58  来源:igfitidea点击:

Android - Activity Not Found Exception

android

提问by James Testa

I am using startActivity to call another Activity and I get the "Activity Not Found Exception". Here is my code:

我正在使用 startActivity 来调用另一个 Activity 并且我得到“Activity Not Found Exception”。这是我的代码:

  TextView textView = (TextView) itemClicked;
  String strText = textView.getText().toString();
  String key = "symptom";
  Intent mIntent = new Intent(symptomActivity.this, symptomRemedyActivity.class);
  Bundle mBundle = new Bundle();
  mBundle.putString(key, strText);
  mIntent.putExtras(mBundle);
  startActivity(mIntent);

Here is the Logcat output:

这是 Logcat 的输出:

INFO/ActivityManager(59): Displayed activity com.android.homeopathy/.HomeopathyActivity: 5542 ms (total 39089 ms)
INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x3283e0:0x3284ec] in 627000 ns
INFO/ActivityManager(59): Starting activity: Intent { cmp=com.android.homeopathy/.symptomActivity }
INFO/ActivityManager(59): Displayed activity com.android.homeopathy/.symptomActivity: 2706 ms (total 2706 ms)
INFO/ActivityManager(59): Starting activity: Intent { cmp=com.android.homeopathy/.symptomRemedyActivity (has extras) }

Here is the debug window output:

这是调试窗口输出:

    Thread [<1> main] (Suspended (exception ActivityNotFoundException)) 
Instrumentation.checkStartActivityResult(int, Object) line: 1404    
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1378  
symptomActivity(Activity).startActivityForResult(Intent, int) line: 2817    
symptomActivity(Activity).startActivity(Intent) line: 2923  
symptomActivity.onItemClick(AdapterView, View, int, long) line: 67    
ListView(AdapterView).performItemClick(View, int, long) line: 284   
ListView.performItemClick(View, int, long) line: 3382   
AbsListView$PerformClick.run() line: 1696   
ViewRoot(Handler).handleCallback(Message) line: 587 
ViewRoot(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 4627    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 521  
ZygoteInit$MethodAndArgsCaller.run() line: 868  
ZygoteInit.main(String[]) line: 626 
NativeStart.main(String[]) line: not available [native method]  

symptomRemedyActivity is another activity in my project. Is there something I need to do like importing symptomRemedyActivity so that startActivity can see symptomRemedyActivity, to remove this "Activity Not Found Exception"?

症状补救活动是我项目中的另一个活动。有什么我需要做的事情,比如导入symbolRemedyActivity,以便startActivity可以看到symbolicRemedyActivity,以删除这个“Activity Not Found Exception”?

回答by Unfrog

I know this is an old post, but it's on top of the google search at the moment, so for anyone who would come here later: ActivityNotFoundcan be caused by unhandled exceptions in your onCreatein the activity you're trying to create. It took me a while to notice that I was causing a nullPointerExceptionthere, because I wasn't looking for it.

我知道这是一篇旧帖子,但它目前在 google 搜索之上,所以对于以后会来这里的任何人:ActivityNotFound可能是由onCreate您尝试创建的活动中未处理的异常引起的。我花了一段时间才注意到我在nullPointerException那里造成了一个,因为我没有在寻找它。

回答by I82Much

Did you list the activity (symtomRemedyActivity) within your AndroidManifest.xml file?

您是否在 AndroidManifest.xml 文件中列出了活动 (symtomRemedyActivity)?

回答by Najeebullah Shah

Make sure you have added the following to the Manifest File

确保您已将以下内容添加到清单文件中

    <activity
        android:name=".YourActivity"
        >
    </activity>

回答by ckp

Stuck with the same error for an hour only to realize that I have to clean and build again. Apparently, some times changes in xml do not reflect until we clean and rebuild.

被同样的错误困了一个小时才意识到我必须再次清理和构建。显然,有时 xml 中的更改在我们清理和重建之前不会反映出来。

回答by Stéphane de Luca

You certainly forgot to declare the activity in the manifest file AndroidManifest.xml as follows (you need to inject the value you actually got):

您肯定忘记在清单文件 AndroidManifest.xml 中声明活动如下(您需要注入您实际获得的值):

   <activity
        android:name="symptomRemedyActivity"
        android:label="@string/title_activity_ symptomRemedy"
        android:parentActivityName="MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="MainActivity" />
    </activity>

回答by Pehlaj

Try adding activity to AndroidManifest.xml

尝试将活动添加到AndroidManifest.xml

<activity android:name=".MyActivity" />

回答by Leo Kong

Not only need you add your Activity in AndroidMainifest.xml like this:

您不仅需要像这样在 AndroidMainifest.xml 中添加您的 Activity:

<activity 
        android:name=".MyActivity"
       ></activity>

but also you should confirm your package path.

但你也应该确认你的包路径。

For example,my activity is in com.demo package. The head of the AndroidMainifest should write the same package path,like this:

例如,我的活动在 com.demo 包中。AndroidMainifest 的头部应该写相同的包路径,像这样:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.demo"
   android:versionCode="1"
   android:versionName="1.0" >

回答by Tarun Jain

In addition to the answer which Unfrog has given.

除了Unfrog给出的答案。

One way to get the NullPointerExceptionis to execute a code which is referring to the view parts before the setContentView().

获取 的一种方法NullPointerException是执行引用setContentView().

回答by Umesh N

Multiple Application tags in Manifest can cause this.

Manifest 中的多个 Application 标签可能会导致这种情况。

回答by Erick Sitorus

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.salvopaverani.databes"
android:versionCode="1"
android:versionName="1.1" >

At manifest file, i try to change the android:versionName from 1.0 to 1.1 and everything OK.

在清单文件中,我尝试将 android:versionName 从 1.0 更改为 1.1,一切正常。