Question

I have an ASUS Eee Tab (Transformer Prime TF201 Android v4.1.1). I was reading the API on Geofencing and downloaded the sample app here below on to my device => http://developer.android.com/training/location/geofencing.html. But it terminates when i open it.

I have set the target sdk = 16 in the AndroidManifest.xml file

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>
Was it helpful?

Solution

@stud91 I have Download Sample Project from above Url , And I have changed some Basic things

  1. Create "libs" folder
  2. Put android-support-v4.jar and google-play-services.jar Jar files

And Run sample project It works like a charm. you can find google-play-services_lib from "adt-bundle-windows-x86\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs" I think you have used Goolge package for that Remove this package. Remove all reference Which you have created for this project. Clean your sample project and Enjoy. my sample project's structure and out put

OTHER TIPS

according to official Android Team Creating and Monitoring Geofences u should Set Up Google Play Services SDK that run on The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher.

in geofences trianing link say that:

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. 

I had the same problem starting an Activity which extends MapActivity. It took some time and research to find the answer. Adding uses-library in manifest.xml under application tag fixed the issue for me:

<uses-library android:name="com.google.android.maps" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top