最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Android应用中进入子页面Activity出错:Thread main Suspended exception ActivityNotFoundException

Android crifan 3917浏览 0评论

【问题】

调试某个安卓应用期间,点击某个Activity子页面“校园周边”:

android app into some sub page activity

结果出错:

xxx  [Android Application]	
DalvikVM[localhost:8600]	
Thread [<1> main] (Suspended (exception ActivityNotFoundException))	
<VM does not provide monitor information>	
Instrumentation.checkStartActivityResult(int, Object) line: 1639	
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int, Bundle) line: 1435	
MainActivity(Activity).startActivityForResult(Intent, int, Bundle) line: 3465	
MainActivity(Activity).startActivityForResult(Intent, int) line: 3420	
MainActivity(FragmentActivity).startActivityForResult(Intent, int) line: 839	
MainActivity(Activity).startActivity(Intent, Bundle) line: 3668	
MainActivity(Activity).startActivity(Intent) line: 3636	
SchoolNearbyActivity.launch(Context) line: 46	
SchoolFragment.onClick(View) line: 146	
RelativeLayout(View).performClick() line: 4446	
View$PerformClick.run() line: 18480	
Handler.handleCallback(Message) line: 733	
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 95	
Looper.loop() line: 136	
ActivityThread.main(String[]) line: 5314	
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]	
Method.invoke(Object, Object...) line: 515	
ZygoteInit$MethodAndArgsCaller.run() line: 864	
ZygoteInit.main(String[]) line: 680	
NativeStart.main(String[]) line: not available [native method]	
Thread [<10> Binder_2] (Running)	
Thread [<9> Binder_1] (Running)	
Daemon Thread [<11> [email protected]@43dd4b30] (Running)	
Thread [<12> PriorityExecutor #1] (Running)	
Thread [<13> Binder_3] (Running)	
Thread [<17> uil-pool-2-thread-2] (Running)	
Thread [<16> uil-pool-2-thread-1] (Running)	
Thread [<19> WifiManager] (Running)	
Thread [<21> PriorityExecutor #2] (Running)	
Thread [<22> PriorityExecutor #3] (Running)	
Thread [<20> pool-3-thread-1] (Running)	
Thread [<23> uil-pool-2-thread-3] (Running)	
Thread [<24> Binder_4] (Running) 

如图:

Thread main Suspended exception ActivityNotFoundException

【折腾过程】

1.看起来像是,少了对应的activity。

但是实际上,此处是存在对应的SchoolNearbyActivity的代码的。

不过之前的确是已经移动该类到子文件夹school中了:

has move SchoolNearbyActivity.java to school under activity

但是对应的类的package已经变成了:

package com.xxx.zzzzzz.activity.school;

啊,所以不应该再出错才对。

 

2.并且看到调试期间的activity传递进去的,好像也是正常的:

passed parameter mComponent mClass seem normal

然后此处的checkStartActivityResult的返回值是-2:

debug checkStartActivityResult return minus 2

3.搜:

checkStartActivityResult –2

没找到有价值的。

4.再搜:

Suspended exception ActivityNotFoundException

参考:

android – Suspended (exception ActivityNotFoundException) – Stack Overflow

去看看此处的AndroidManifest.xml。发现的确是当前的值是旧的:

AndroidManifest.xml activity name is previous one

去把:

        <activity
            android:name=".activity.SchoolNearbyActivity"
            android:screenOrientation="portrait" >
        </activity>

改为:

        <activity
            android:name=".activity.school.SchoolNearbyActivity"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".activity.school.SchoolMarketActivity"
            android:screenOrientation="portrait" >
        </activity>

如图:

AndroidManifest.xml added path and activity name

结果:

就正常了,就可以找到该activity了,然后可以进入子页面了:

android into sub page normal

【总结】

此处调试安卓程序出错:

Thread main Suspended exception ActivityNotFoundException

原因是:

没有及时更新程序的AndroidManifest.xml中对于activity的配置。

此处从:

        <activity
            android:name=".activity.SchoolNearbyActivity"
            android:screenOrientation="portrait" >
        </activity>

改为:

        <activity
            android:name=".activity.school.SchoolNearbyActivity"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".activity.school.SchoolMarketActivity"
            android:screenOrientation="portrait" >
        </activity>

其中:

SchoolNearbyActivity.java是从activity路径下,移动到了activity/school下面;

而SchoolMarketActivity.java是activity/school下新增加的。

 

心得:

以后将安卓程序代码(xxxActivity.java)移动的时候,除了记得修改Package和import之外,还要记得更新(Activity在)AndroidManifest.xml中的路径配置。

转载请注明:在路上 » 【已解决】Android应用中进入子页面Activity出错:Thread main Suspended exception ActivityNotFoundException

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.194 seconds, using 22.12MB memory