gpt4 book ai didi

java - Android 新增功能 : java. lang.RuntimeException:无法实例化 Activity ComponentInfo

转载 作者:行者123 更新时间:2023-12-02 07:44:51 25 4
gpt4 key购买 nike

这是我的 MyTasteActivity 代码:

package MyTaste;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MyTasteActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);

}
}

这是我的 XML Android list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="My.Taste.App"
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=".MyTaasteActivity"
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>

</manifest>

那么为什么我总是收到此错误:

06-14 20:22:48.779: E/AndroidRuntime(749): FATAL EXCEPTION: main

06-14 20:22:48.779: E/AndroidRuntime(749): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{My.Taste.App/My.Taste.App.MyTasteActivity}: java.lang.ClassNotFoundException: My.Taste.App.MyTasteActivity

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.ActivityThread.access$600(ActivityThread.java:123)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)

06-14 20:22:48.779: E/AndroidRuntime(749): at
android.os.Handler.dispatchMessage(Handler.java:99)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.os.Looper.loop(Looper.java:137)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.ActivityThread.main(ActivityThread.java:4424)

06-14 20:22:48.779: E/AndroidRuntime(749): at java.lang.reflect.Method.invokeNative(Native Method)

06-14 20:22:48.779: E/AndroidRuntime(749): at java.lang.reflect.Method.invoke(Method.java:511)

06-14 20:22:48.779: E/AndroidRuntime(749): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

06-14 20:22:48.779: E/AndroidRuntime(749): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

06-14 20:22:48.779: E/AndroidRuntime(749): at dalvik.system.NativeStart.main(Native Method)

06-14 20:22:48.779: E/AndroidRuntime(749): Caused by: java.lang.ClassNotFoundException: My.Taste.App.MyTasteActivity

06-14 20:22:48.779: E/AndroidRuntime(749): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)

06-14 20:22:48.779: E/AndroidRuntime(749): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

06-14 20:22:48.779: E/AndroidRuntime(749): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)

06-14 20:22:48.779: E/AndroidRuntime(749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)

06-14 20:22:48.779: E/AndroidRuntime(749): ... 11 more

AVD 将显示消息“不幸的是,MyTaste 已停止。”我不知道出了什么问题,我已经重新安装了几次Android SDK。

最佳答案

您将包指定为:

package="My.Taste.App"

而代码中指定的包是:

package MyTaste;

我认为一致性会解决这个问题

编辑:下面的遮阳篷显示了另一个一致性问题。

关于java - Android 新增功能 : java. lang.RuntimeException:无法实例化 Activity ComponentInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11040903/

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