有時我的應用程序崩潰,當我嘗試在應用程序中打開一個瀏覽器增加了,這裏是我的代碼:ActivityNotFoundException打開瀏覽器時
public void onBannerClick(final View view){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(mBannerURL));
startActivity(intent);
,這是堆棧跟蹤我得到:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:2179)
at android.view.View.performClick(View.java:2535)
at android.view.View$PerformClick.run(View.java:9130)
at android.os.Handler.handleCallback(Handler.java:618)
at android.os.Handler.dispatchMessage(Handler.java:123)
at android.os.Looper.loop(SourceFile:351)
at android.app.ActivityThread.main(ActivityThread.java:3850)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:538)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:538)
at android.view.View$1.onClick(View.java:2174)
... 11 more
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://xxxxxxxxx.xx }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1449)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
at android.app.Activity.startActivityForResult(Activity.java:2878)
at android.app.Activity.startActivity(Activity.java:2984)
at com.XXXXXXXXX.XXXXXXXXXXXXX.MainActivity.onBannerClick(MainActivity.java:830)
... 14 more
可以any1請幫忙嗎?
如果您不希望應用程序崩潰,則可以在'startActivity()'周圍添加'try ... catch'塊。現在至於爲什麼它會崩潰,這將需要更多的努力,可能是它被髮送到 – Russ 2012-07-07 19:49:17
添加一個try catch塊的實際URL我是一個好主意,謝謝 – 2012-07-07 20:38:00