gpt4 book ai didi

安卓模拟器停止

转载 作者:行者123 更新时间:2023-11-29 00:39:15 25 4
gpt4 key购买 nike

所以我一直在让它运行时遇到问题。这是直接从 android 基础培训中提取的教程。我收到以下错误消息:

05-11 06:59:39.457: W/dalvikvm(623): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 05-11 06:59:39.617: E/AndroidRuntime(623): FATAL EXCEPTION: main 05-11 06:59:39.617: E/AndroidRuntime(623): java.lang.IllegalStateException: Could not execute method of the activity 05-11 06:59:39.617: E/AndroidRuntime(623): at android.view.View$1.onClick(View.java:3044) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.view.View.performClick(View.java:3511) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.view.View$PerformClick.run(View.java:14105) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.os.Handler.handleCallback(Handler.java:605) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.os.Handler.dispatchMessage(Handler.java:92) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.os.Looper.loop(Looper.java:137) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.app.ActivityThread.main(ActivityThread.java:4424) 05-11 06:59:39.617: E/AndroidRuntime(623): at java.lang.reflect.Method.invokeNative(Native Method) 05-11 06:59:39.617: E/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:511) 05-11 06:59:39.617: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 05-11 06:59:39.617: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-11 06:59:39.617: E/AndroidRuntime(623): at dalvik.system.NativeStart.main(Native Method) 05-11 06:59:39.617: E/AndroidRuntime(623): Caused by: java.lang.reflect.InvocationTargetException 05-11 06:59:39.617: E/AndroidRuntime(623): at java.lang.reflect.Method.invokeNative(Native Method) 05-11 06:59:39.617: E/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:511) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.view.View$1.onClick(View.java:3039) 05-11 06:59:39.617: E/AndroidRuntime(623): ... 11 more 05-11 06:59:39.617: E/AndroidRuntime(623): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.namespace/com.example.namespace.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 05-11 06:59:39.617: E/AndroidRuntime(623): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.app.Activity.startActivityForResult(Activity.java:3190) 05-11 06:59:39.617: E/AndroidRuntime(623): at android.app.Activity.startActivity(Activity.java:3297) 05-11 06:59:39.617: E/AndroidRuntime(623): at com.example.namespace.MyFirstAppActivity.sendMessage(MyFirstAppActivity.java:25) 05-11 06:59:39.617: E/AndroidRuntime(623): ... 14 more 05-11 06:59:40.477: I/dalvikvm(623): threadid=3: reacting to signal 3

这是我的两个java文件,

package com.example.namespace;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class DisplayMessageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MyFirstAppActivity.EXTRA_MESSAGE);

// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);

setContentView(textView);
}
}

package com.example.namespace;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MyFirstAppActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}


public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}

这是我的 androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.namespace"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="15" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name="com.example.myapp.DisplayMessageActivity" />
<activity
android:name=".MyFirstAppActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

和我的 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="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"/>
</LinearLayout>

每次我运行它,在调用“sendMessage”的那一刻,我得到“不幸的是,myFirstApp 已停止。”有什么建议吗?

最佳答案

我觉得应该是这样

  android:name="com.example.myapp.DisplayMessageActivity"

改为

  android:name="com.example.namespace.DisplayMessageActivity"

因为没有包com.example.myapp

关于安卓模拟器停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10547065/

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