![](/img/trans.png)
[英]Android ClassNotFoundException using actionbarsherlock library
[英]Android: ClassNotFoundException when running ActionBarSherlock-Plugin-Maps
我正在嘗試設置一個使用Jake Wharton的ActionBarSherlock和ActionBarSherlock-Plugin-Maps的示例項目。 我按照這里和這里的說明進行操作。 我不一定需要碎片。 這是我創建的簡單類。
package com.example.actionbarsherlock;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockMapActivity;
public class MainActivity extends SherlockMapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
雖然我試圖遵循確切的描述,但是當我啟動應用程序時,我最終會遇到ClassNotFoundException
。 這是堆棧跟蹤。
Unable to resolve superclass of Lcom/actionbarsherlock/app/SherlockMapActivity; (729)
Link of class 'Lcom/actionbarsherlock/app/SherlockMapActivity;' failed
Unable to resolve superclass of Lcom/example/actionbarsherlock/MainActivity; (533)
Link of class 'Lcom/example/actionbarsherlock/MainActivity;' failed
D/AndroidRuntime(408): Shutting down VM
threadid=3: thread exiting with uncaught exception (group=0x4001b188)
Uncaught handler: thread main exiting due to uncaught exception
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.actionbarsherlock/com.example.actionbarsherlock.MainActivity}:
java.lang.ClassNotFoundException: com.example.actionbarsherlock.MainActivity
in loader dalvik.system.PathClassLoader@44e8ca40
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.actionbarsherlock.MainActivity
in loader dalvik.system.PathClassLoader@44e8ca40
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
... 11 more
threadid=7: reacting to signal 3
Unable to open stack trace file '/data/anr/traces.txt': Permission denied
我之前測試過該庫並創建了一個SherlockActivity
的子類,它工作正常。 在這樣做時,我注意到當我忘記在AndroidManifest.xml
配置android:theme
設置時會發生相同的ClassNotFoundException
。 以下是( SherlockActivity
和SherlockMapActivity
)示例項目的文件,以防萬一:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:theme="@style/Theme.Sherlock"
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
更新:
按照Raghav Sood和M Mohsin Naeem的建議添加uses-library
設置后,我會遇到以下消息。
Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
這是我項目設置的屏幕截圖。
編輯:
也許我的actionbarsherlocktest項目的.classpath
文件有助於......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/actionbarsherlock-plugin-maps-4.1.0.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
庫項目的.classpath
文件看起來完全相同。
INSTALL_FAILED_MISSING_SHARED_LIBRARY
錯誤消息的解決方案 。
出於某些原因,Eclipse總是啟動為API級別7配置但沒有Google API的模擬器。 我無法強迫它選擇“啟用地圖”的模擬器。 刪除“無地圖”模擬器后,應用程序成功啟動。 你知道這會怎么樣嗎?
摘要:
最后,我讓它運行起來。 以下是我想分享的一些經驗。
action-support-v4.jar
更新為最新版本。 actionbarsherlock-plugin-map-xyzjar
到庫項目的libs
文件夾中。 action-support-v4.jar
或actionbarsherlock-plugin-map-xyzjar
到您的主項目。 也沒有必要將任何.jar文件添加到主項目的構建路徑中。 您將遇到此錯誤的原因只有三個:
你還應該添加
<uses-library android:name="com.google.android.maps" />
到您的清單文件。
你錯過了第8步。
<uses-library android:name="com.google.android.maps" />
你需要在清單文件中添加它。
就這樣吧
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:theme="@style/Theme.Sherlock"
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.