【问题】
调试某个安卓应用期间,点击某个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)
如图:
【折腾过程】
1.看起来像是,少了对应的activity。
但是实际上,此处是存在对应的SchoolNearbyActivity的代码的。
不过之前的确是已经移动该类到子文件夹school中了:
但是对应的类的package已经变成了:
package com.xxx.zzzzzz.activity.school;
啊,所以不应该再出错才对。
2.并且看到调试期间的activity传递进去的,好像也是正常的:
然后此处的checkStartActivityResult的返回值是-2:
3.搜:
checkStartActivityResult –2
没找到有价值的。
4.再搜:
Suspended exception ActivityNotFoundException
参考:
android – Suspended (exception ActivityNotFoundException) – Stack Overflow
去看看此处的AndroidManifest.xml。发现的确是当前的值是旧的:
去把:
<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>
如图:
结果:
就正常了,就可以找到该activity了,然后可以进入子页面了:
【总结】
此处调试安卓程序出错:
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