应用程序按钮活动意外停止。请再试一次

时间:2013-12-22 18:53:58

标签: java android

我是Android开发的新手。运行以下代码时没有错误。但是在运行模拟器并单击按钮之后。有一条错误消息,例如“应用程序按钮活动意外停止。请再试一次我还在添加logcat信息。

    12-22 23:59:08.402: D/AndroidRuntime(332): Shutting down VM
12-22 23:59:08.402: W/dalvikvm(332): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-22 23:59:08.472: E/AndroidRuntime(332): FATAL EXCEPTION: main
12-22 23:59:08.472: E/AndroidRuntime(332): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=google.com }
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.app.Activity.startActivityForResult(Activity.java:2827)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.app.Activity.startActivity(Activity.java:2933)
12-22 23:59:08.472: E/AndroidRuntime(332):  at com.example.button_example.MainActivity$1.onClick(MainActivity.java:32)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.view.View.performClick(View.java:2485)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.view.View$PerformClick.run(View.java:9080)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.os.Handler.handleCallback(Handler.java:587)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.os.Looper.loop(Looper.java:123)
12-22 23:59:08.472: E/AndroidRuntime(332):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-22 23:59:08.472: E/AndroidRuntime(332):  at java.lang.reflect.Method.invokeNative(Native Method)
12-22 23:59:08.472: E/AndroidRuntime(332):  at java.lang.reflect.Method.invoke(Method.java:507)
12-22 23:59:08.472: E/AndroidRuntime(332):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-22 23:59:08.472: E/AndroidRuntime(332):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-22 23:59:08.472: E/AndroidRuntime(332):  at dalvik.system.NativeStart.main(Native Method)
12-23 00:04:08.634: I/Process(332): Sending signal. PID: 332 SIG: 9
12-23 00:06:49.022: W/ActivityThread(377): Application com.example.button_example is waiting for the debugger on port 8100...
12-23 00:06:49.042: I/System.out(377): Sending WAIT chunk
12-23 00:06:49.202: I/dalvikvm(377): Debugger is active
12-23 00:06:49.256: I/System.out(377): Debugger has connected
12-23 00:06:49.256: I/System.out(377): waiting for debugger to settle...
12-23 00:06:49.452: I/System.out(377): waiting for debugger to settle...
12-23 00:06:49.662: I/System.out(377): waiting for debugger to settle...
12-23 00:06:49.892: I/System.out(377): waiting for debugger to settle...
12-23 00:06:50.092: I/System.out(377): waiting for debugger to settle...
12-23 00:06:50.292: I/System.out(377): waiting for debugger to settle...
12-23 00:06:50.492: I/System.out(377): waiting for debugger to settle...
12-23 00:06:50.692: I/System.out(377): waiting for debugger to settle...
12-23 00:06:50.905: I/System.out(377): waiting for debugger to settle...
12-23 00:06:51.102: I/System.out(377): waiting for debugger to settle...
12-23 00:06:51.305: I/System.out(377): waiting for debugger to settle...
12-23 00:06:51.512: I/System.out(377): waiting for debugger to settle...
12-23 00:06:51.714: I/System.out(377): waiting for debugger to settle...
12-23 00:06:51.912: I/System.out(377): waiting for debugger to settle...
12-23 00:06:52.115: I/System.out(377): waiting for debugger to settle...
12-23 00:06:52.323: I/System.out(377): debugger has settled (1482)
12-23 00:07:04.702: W/ActivityThread(419): Application com.example.button_example is waiting for the debugger on port 8100...
12-23 00:07:04.752: I/System.out(419): Sending WAIT chunk
12-23 00:07:04.772: I/dalvikvm(419): Debugger is active
12-23 00:07:04.972: I/System.out(419): Debugger has connected
12-23 00:07:04.972: I/System.out(419): waiting for debugger to settle...
12-23 00:07:05.172: I/System.out(419): waiting for debugger to settle...
12-23 00:07:05.372: I/System.out(419): waiting for debugger to settle...
12-23 00:07:05.574: I/System.out(419): waiting for debugger to settle...
12-23 00:07:05.773: I/System.out(419): waiting for debugger to settle...
12-23 00:07:05.982: I/System.out(419): waiting for debugger to settle...
12-23 00:07:06.182: I/System.out(419): waiting for debugger to settle...
12-23 00:07:06.382: I/System.out(419): waiting for debugger to settle...
12-23 00:07:06.582: I/System.out(419): waiting for debugger to settle...
12-23 00:07:06.801: I/System.out(419): waiting for debugger to settle...
12-23 00:07:07.002: I/System.out(419): waiting for debugger to settle...
12-23 00:07:07.203: I/System.out(419): debugger has settled (1353)

mainactivity.java的示例代码

package com.example.button_example;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        addListenerOnButton();

    }

    public void addListenerOnButton() {

        button = (Button) findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                Intent browsercontent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.com"));
                startActivity(browsercontent);


            }
        });

    }



}

activity_main.xml的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button - Go to mkyong.com" />

</LinearLayout>

我从www.mkyong.com/android/android-button-example/

获得了此代码

1 个答案:

答案 0 :(得分:3)

尝试将协议添加到您的uri:

new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));