我正在eclipse中编写一个基本的应用程序。 MainActivity.java类如下:
public class MainActivity extends ActionBarActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textview);
tv.setText("Hello Billal");
}
}
我的清单文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidclass.simpleprogram"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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>
但是当我运行这个应用程序时,我会遇到异常。 logcat显示以下错误。
12-04 12:50:26.466: E/AndroidRuntime(1168): FATAL EXCEPTION: main
12-04 12:50:26.466: E/AndroidRuntime(1168): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidclass.simpleprogram/com.androidclass.simpleprogram.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.androidclass.simpleprogram.MainActivity" on path: /data/app/com.androidclass.simpleprogram-2.apk
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.os.Looper.loop(Looper.java:137)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.ActivityThread.main(ActivityThread.java:5041)
12-04 12:50:26.466: E/AndroidRuntime(1168): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 12:50:26.466: E/AndroidRuntime(1168): at java.lang.reflect.Method.invoke(Method.java:511)
12-04 12:50:26.466: E/AndroidRuntime(1168): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 12:50:26.466: E/AndroidRuntime(1168): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 12:50:26.466: E/AndroidRuntime(1168): at dalvik.system.NativeStart.main(Native Method)
12-04 12:50:26.466: E/AndroidRuntime(1168): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.androidclass.simpleprogram.MainActivity" on path: /data/app/com.androidclass.simpleprogram-2.apk
12-04 12:50:26.466: E/AndroidRuntime(1168): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-04 12:50:26.466: E/AndroidRuntime(1168): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-04 12:50:26.466: E/AndroidRuntime(1168): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
12-04 12:50:26.466: E/AndroidRuntime(1168): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
12-04 12:50:26.466: E/AndroidRuntime(1168): ... 11 more
如何解决此错误?