2015-09-12 176 views
0

我嘗試使用GooglePlaceAPI獲取當前位置 當我將Google Play服務用作依賴關係時,它會導致無法找到我的主要活動的錯誤。 以下是代碼:無法實例化活動

​​

我的日誌是在這裏:

09-12 21:53:51.796: W/ResourceType(9470): Found multiple library tables, ignoring... 
09-12 21:53:51.802: I/art(9470): Rejecting re-init on previously-failed class java.lang.Class<com.example.myproject.MainActivity> 
09-12 21:53:51.804: D/AndroidRuntime(9470): Shutting down VM 
09-12 21:53:51.823: E/AndroidRuntime(9470): FATAL EXCEPTION: main 
09-12 21:53:51.823: E/AndroidRuntime(9470): Process: com.example.myproject, PID: 9470 
09-12 21:53:51.823: E/AndroidRuntime(9470): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myproject/com.example.myproject.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myproject.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myproject-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.ActivityThread.access$800(ActivityThread.java:149) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.os.Handler.dispatchMessage(Handler.java:102) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.os.Looper.loop(Looper.java:211) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.ActivityThread.main(ActivityThread.java:5317) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at java.lang.reflect.Method.invoke(Native Method) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at java.lang.reflect.Method.invoke(Method.java:372) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) 
09-12 21:53:51.823: E/AndroidRuntime(9470): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myproject.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.myproject-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.Instrumentation.newActivity(Instrumentation.java:1065) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246) 
09-12 21:53:51.823: E/AndroidRuntime(9470):  ... 10 more 
09-12 21:53:51.823: E/AndroidRuntime(9470):  Suppressed: java.lang.NoClassDefFoundError: com.example.myproject.MainActivity 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at dalvik.system.DexFile.defineClassNative(Native Method) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at dalvik.system.DexFile.defineClass(DexFile.java:226) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at dalvik.system.DexPathList.findClass(DexPathList.java:321) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   ... 14 more 
09-12 21:53:51.823: E/AndroidRuntime(9470):  Suppressed: java.lang.ClassNotFoundException: com.example.myproject.MainActivity 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at java.lang.Class.classForName(Native Method) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
09-12 21:53:51.823: E/AndroidRuntime(9470):   ... 13 more 
09-12 21:53:51.823: E/AndroidRuntime(9470):  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 
09-12 21:53:51.848: I/Process(9470): Sending signal. PID: 9470 SIG: 9 

我的清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.myproject" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="16" 
     android:targetSdkVersion="16" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.myproject.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> 
     <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="MY_KEY"/> 

    </application> 

</manifest> 
+0

看看這個問題在這裏,也許它可以幫助你。 http://stackoverflow.com/questions/19523167/android-classnotfoundexception-didnt-find-class-on-path – Noahnder

+0

@Noahnder我看到這個帖子,它不能解決我的問題 –

回答

0

在Manifest.xml文件試試這個:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.myproject" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="16" 
     android:targetSdkVersion="16" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 

    <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> 
     <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="MY_KEY"/> 

    </application> 

</manifest> 

因爲它是蘇不清楚在Manifest開頭聲明您的軟件包名稱。

+0

沒有問題仍然存在 –

+0

你採取了嗎?看看這個答案? [這裏](http://stackoverflow.com/questions/24611977/android-locationclient-class-is-deprecated-but-used-in-documentation)。看起來他有同樣的問題。 – Anas

相關問題