我在Mac上的Eclipse中创建了一个新的Android应用程序项目。我设置了Android 4.4.2 sdk。
当我在物理Nexus 7 Tablet中安装此示例项目时,它会引发以下启动错误。我还没有在这个项目中添加任何东西,它只是一个原样创建的示例项目。
遗憾的是已停止
04-13 00:16:05.395: W/dalvikvm(6761): Unable to resolve superclass of Lcom/example/myfinaltest/MainActivity; (2)
04-13 00:16:05.395: W/dalvikvm(6761): Link of class 'Lcom/example/myfinaltest/MainActivity;' failed
04-13 00:16:05.395: D/AndroidRuntime(6761): Shutting down VM
04-13 00:16:05.395: W/dalvikvm(6761): threadid=1: thread exiting with uncaught exception (group=0x415bcba8)
04-13 00:16:05.395: E/AndroidRuntime(6761): FATAL EXCEPTION: main
04-13 00:16:05.395: E/AndroidRuntime(6761): Process: com.example.myfinaltest, PID: 6761
04-13 00:16:05.395: E/AndroidRuntime(6761): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myfinaltest/com.example.myfinaltest.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myfinaltest.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfinaltest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfinaltest-2, /vendor/lib, /system/lib]]
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.os.Looper.loop(Looper.java:136)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-13 00:16:05.395: E/AndroidRuntime(6761): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 00:16:05.395: E/AndroidRuntime(6761): at java.lang.reflect.Method.invoke(Method.java:515)
04-13 00:16:05.395: E/AndroidRuntime(6761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-13 00:16:05.395: E/AndroidRuntime(6761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-13 00:16:05.395: E/AndroidRuntime(6761): at dalvik.system.NativeStart.main(Native Method)
04-13 00:16:05.395: E/AndroidRuntime(6761): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfinaltest.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myfinaltest-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myfinaltest-2, /vendor/lib, /system/lib]]
04-13 00:16:05.395: E/AndroidRuntime(6761): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-13 00:16:05.395: E/AndroidRuntime(6761): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
04-13 00:16:05.395: E/AndroidRuntime(6761): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-13 00:16:05.395: E/AndroidRuntime(6761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-13 00:16:05.395: E/AndroidRuntime(6761): ... 11 more
代码:
package com.example.myfinaltest;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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);
}
}
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfinaltest"
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"
>
<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>
对于values / styles.xml和values-v11 / styles.xml以及values-v14 / styles.xml
所有3 xml的值相同,但是我评论了App主题,因为我看到使用Appcompat库构建错误。
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
-->
<!-- Application theme.
<style name="AppTheme" parent="AppBaseTheme">
</style>
-->
</resources>
答案 0 :(得分:1)
检查您的AndroidManifest.xml,看看您的活动是否定义如下。
<activity
android:name="com.example.myfinaltest.MainActivity"
android:label="@string/app_name" >
</activity>
包名称可能不是&#34; com.example.myfinaltest&#34;在你的情况下。
答案 1 :(得分:0)
由于您使用AppCompat
并扩展ActionBarActivity
,因此您需要指定正确的主题。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfinaltest"
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"> <!-- You need a theme -->
<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>
values/styles.xml
您可以删除所有除 values/styles.xml
之外的所有内容。
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>