gpt4 book ai didi

java - 应用程序按钮 Activity 意外停止。请重试

转载 作者:行者123 更新时间:2023-12-01 23:20:12 25 4
gpt4 key购买 nike

我是 Android 开发新手。运行以下代码时没有错误。但是运行模拟器并单击按钮后。出现错误消息,例如“应用程序按钮 Activity 已意外停止。请重试” 我还添加了 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/ 获得此代码

最佳答案

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

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

关于java - 应用程序按钮 Activity 意外停止。请重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20732865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com