运行位置更新示例代码时,MainActivity的java.lang.ClassNotFoundException

时间:2014-07-07 06:29:32

标签: android

我正在关注this link的培训教程:。它在运行时给出了一些例外,以下是几个初始的日志跟踪行:

07-07 10:54:51.408: E/AndroidRuntime(31450): FATAL EXCEPTION: main
07-07 10:54:51.408: E/AndroidRuntime(31450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.location/com.example.android.location.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.location.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.location-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.location-1, /vendor/lib, /system/lib]]
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.os.Handler.dispatchMessage(Handler.java:107)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.os.Looper.loop(Looper.java:194)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.ActivityThread.main(ActivityThread.java:5371)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at java.lang.reflect.Method.invokeNative(Native Method)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at java.lang.reflect.Method.invoke(Method.java:525)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at dalvik.system.NativeStart.main(Native Method)
07-07 10:54:51.408: E/AndroidRuntime(31450): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.location.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.location-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.location-1, /vendor/lib, /system/lib]]
07-07 10:54:51.408: E/AndroidRuntime(31450):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-07 10:54:51.408: E/AndroidRuntime(31450):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
07-07 10:54:51.408: E/AndroidRuntime(31450):    ... 11 more

以下是我的清单文件代码

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.location"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:description="@string/app_description"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.android.location.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>
    <service
        android:name="com.example.android.location.ReceiveUpdatesIntentService"
        android:label="@string/app_name"
        android:exported="false"></service>
</application>

我还添加了互联网许可,但它无效

1 个答案:

答案 0 :(得分:1)

我在启动扩展Activity的{​​{1}}时遇到了同样的问题。找到答案花了一些时间和研究。在MapActivity标记下的manifest.xml中添加uses-library修复了问题:

application