這是我的MyTasteActivity代碼:新到Android:了java.lang.RuntimeException:無法實例活動ComponentInfo
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清單:
<?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。
此外,還有在'Android的一個錯字:NAME = 「MyTaasteActivity。」' - 一個額外的 「一」。 –