地理围栏(Android示例应用程序)java.lang.ClassNotFoundException MainActivity

6
我有一台ASUS Eee Tab(Transformer Prime TF201 Android v4.1.1)。我正在阅读关于地理围栏的API,并将下面的示例应用程序下载到我的设备上 => http://developer.android.com/training/location/geofencing.html。但是当我打开它时,它会终止运行。
我已经在AndroidManifest.xml文件中设置了目标sdk = 16。
LogCat
06-04 19:39:34.176: E/AndroidRuntime(2596): FATAL EXCEPTION: main
06-04 19:39:34.176: E/AndroidRuntime(2596): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.geofence/com.example.android.geofence.MainActivity}: java.lang.ClassNotFoundException: com.example.android.geofence.MainActivity
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.os.Looper.loop(Looper.java:137)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.ActivityThread.main(ActivityThread.java:4745)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at java.lang.reflect.Method.invokeNative(Native Method)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at java.lang.reflect.Method.invoke(Method.java:511)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at dalvik.system.NativeStart.main(Native Method)
06-04 19:39:34.176: E/AndroidRuntime(2596): Caused by: java.lang.ClassNotFoundException: com.example.android.geofence.MainActivity
06-04 19:39:34.176: E/AndroidRuntime(2596):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
06-04 19:39:34.176: E/AndroidRuntime(2596):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
06-04 19:39:34.176: E/AndroidRuntime(2596):     ... 11 more

enter image description here

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2013 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <!--
        Requests address-level location access, which is usually
        necessary for geofencing
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:allowBackup="true" >

        <!-- The app's entry point -->
        <activity
            android:name="com.example.android.geofence.MainActivity"
            android:label="@string/title_activity_geofence" >
            <intent-filter>
                <!--
                    This activity is triggered when the system
                    tries to start the app's main activity
                -->
                <action android:name="android.intent.action.MAIN" />

                <!--
                    This activity should be linked to the app's Launcher icon
                 -->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="com.example.android.geofence.ReceiveTransitionsIntentService" android:exported="false"></service>
    </application>

</manifest>

请发布您的Logcat或提供更多信息。 - Alberto
类未找到异常: com.example.android.geofence.MainActivity,请检查您的包和类名称是否正确。同时请检查清单文件。 - Alberto
你的项目配置文件是什么?有可能你没有正确地设置导出到 APK 的类。 - Brian
我的怀疑是问题类似于这个:https://dev59.com/B2gv5IYBdhLWcg3wD8yY - Brian
3个回答

1

@stud91 我已从上述网址下载了示例项目,并对一些基本内容进行了更改。

  1. 创建“libs”文件夹
  2. 放置android-support-v4.jar和google-play-services.jar Jar文件

然后运行示例项目,它可以完美地工作。 你可以在 "adt-bundle-windows-x86\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs" 中找到google-play-services_lib。 我认为你已经使用了Google包,所以请删除这个包。删除你为此项目创建的所有引用。清理你的示例项目并享受。 我的示例项目结构输出


0
根据官方 Android 团队的说法创建和监控地理围栏,您应该设置 Google Play 服务 SDK,在运行基于 Android 4.2.2 或更高版本的 Google APIs 平台的 AVD 上运行它。
在地理围栏培训链接中提到:
Note: To make your app compatible with platform version 1.6 and later, the activity that displays the DialogFragment must subclass FragmentActivity instead of Activity. Using FragmentActivity also allows you to call getSupportFragmentManager() to display the DialogFragment. 

0

我在启动一个继承了MapActivityActivity时遇到了同样的问题。花费了一些时间和研究才找到答案。在manifest.xml文件中,在application标签下添加uses-library解决了我的问题:

<uses-library android:name="com.google.android.maps" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接