我正在尝试通过机器人介绍教程创建MyFirstApp应用程序,当它启动时立即崩溃说不幸的是,MyFirstApp已停止。代码中没有错误,但这里是logcat输出:
03-30 21:10:54.529: W/dalvikvm(27006): Unable to resolve superclass of Lcom/example/myfirstapp/MainActivity; (5)
03-30 21:10:54.529: W/dalvikvm(27006): Link of class 'Lcom/example/myfirstapp/MainActivity;' failed
03-30 21:10:54.529: D/AndroidRuntime(27006): Shutting down VM
03-30 21:10:54.529: W/dalvikvm(27006): threadid=1: thread exiting with uncaught exception (group=0x416feda0)
03-30 21:10:54.529: E/AndroidRuntime(27006): FATAL EXCEPTION: main
03-30 21:10:54.529: E/AndroidRuntime(27006): Process: com.example.myfirstapp, PID: 27006
03-30 21:10:54.529: E/AndroidRuntime(27006): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-9.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfirstapp-9, /vendor/lib, /system/lib]]
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.ActivityThread.access$900(ActivityThread.java:161)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.os.Handler.dispatchMessage(Handler.java:102)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.os.Looper.loop(Looper.java:157)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.ActivityThread.main(ActivityThread.java:5356)
03-30 21:10:54.529: E/AndroidRuntime(27006): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 21:10:54.529: E/AndroidRuntime(27006): at java.lang.reflect.Method.invoke(Method.java:515)
03-30 21:10:54.529: E/AndroidRuntime(27006): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-30 21:10:54.529: E/AndroidRuntime(27006): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-30 21:10:54.529: E/AndroidRuntime(27006): at dalvik.system.NativeStart.main(Native Method)
03-30 21:10:54.529: E/AndroidRuntime(27006): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-9.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfirstapp-9, /vendor/lib, /system/lib]]
03-30 21:10:54.529: E/AndroidRuntime(27006): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
03-30 21:10:54.529: E/AndroidRuntime(27006): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-30 21:10:54.529: E/AndroidRuntime(27006): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
03-30 21:10:54.529: E/AndroidRuntime(27006): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
03-30 21:10:54.529: E/AndroidRuntime(27006): ... 11 more
这是AndroidManifest.xml和MainActivity.java文件:
package com.example.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
这是清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myfirstapp.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>
activiy_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myfirstapp.MainActivity"
tools:ignore="MergeRootFrame" />