android两个应用跳转出现错误我在一个应用中做了一个对话框,点击确定时打开另一个应用。相关代码如下Java c
android两个应用跳转出现错误
我在一个应用中做了一个对话框,点击确定时打开另一个应用。相关代码如下
Java codeDialog alertDialog = new AlertDialog.Builder(this). setTitle("确定删除?"). setMessage("此图片是上层图片,您确定进行提取信息吗?"). setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String packgename="com.tmxk" ; String classname="com.tmxk.ComsystemActivity"; ComponentName comp = new ComponentName("packgename","classname"); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(comp); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }). create(); alertDialog.show();
可是出现了程序异常中止,logccat中信息为
07-18 02:19:49.333: ERROR/AndroidRuntime(2066): Uncaught handler: thread main exiting due to uncaught exception
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): android.content.ActivityNotFoundException: Unable to find explicit activity class {packgename/classname}; have you declared this activity in your AndroidManifest.xml?
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.app.Activity.startActivityForResult(Activity.java:2749)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.app.Activity.startActivity(Activity.java:2855)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at com.xd.tmxk.DialogActivity$1.onClick(DialogActivity.java:37)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.os.Looper.loop(Looper.java:123)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-18 02:19:49.370: ERROR/AndroidRuntime(2066): at dalvik.system.NativeStart.main(Native Method)
[解决办法]07-18 02:19:49.370: ERROR/AndroidRuntime(2066): android.content.ActivityNotFoundException: Unable to find explicit activity class {packgename/classname}; have you declared this activity in your AndroidManifest.xml?
还真是:
String packgename="com.tmxk" ;
String classname="com.tmxk.ComsystemActivity";
ComponentName comp = new ComponentName("packgename","classname");
你设置的是"packgename","classname",不是"com.tmxk", "com.tmxk.ComsystemActivity".
[解决办法]
ComponentName comp = new ComponentName("packgename","classname");
改为
ComponentName comp = new ComponentName(packgename,classname);