Coding android app with google maps v2 - Crashes immediately - android

I am new to app programming, and programming in general. I am still in school for computer science (i'm a sophmore). So please take it easy on me. I hate getting bashed on forums.
My problem is that my app, which will use google maps as the main window crashes immediately. I have posted all my code below, and I am looking for any help to what I might be missing to get this app up and running (or so it does not crash immediately).
A couple things might be wrong:
1) I am now using the SHA1 debug key for this testing stage. Is this right?
2) Do I need to communicate with a type 'GoogleMap' in java to set starting location or anything?
3) I am testing this on my phone (Galaxy SIII) which has worked in the past on simple layouts, but might testing this google maps app need authentication that the phone cannot give?
A couple links I found helpful, up until now:
https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api
Google Maps Android API v2 - Sample Code crashes
Notes on setup: I have added android-support-v4.jar and google-play-services.jar to my reference libraries.
Properties -> Java Build Path, Libraries
Now, Below, this is all the code I have so far!
Java file (Main.java):
package com.MYDOMAINNAME.www;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
xml file (main layout):
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
program manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MYDOMAINNAME.www"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.MYDOMAINNAME.www.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.MYDOMAINNAME.www.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name= "com.google.android.maps" />
<activity
android:name="com.MYDOMAINNAME.www.Main"
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.maps.v2.API_KEY"
android:value="MY SHA1 DEBUG KEY"/>
</application>
</manifest>
So I would ask, is there anything I need to add or subtract to get this going?
Thanks a bunch!
Log Cat:
12-22 14:45:28.482: E/Trace(10174): error opening trace file: No such file or directory (2)
12-22 14:45:28.482: D/ActivityThread(10174): setTargetHeapUtilization:0.25
12-22 14:45:28.482: D/ActivityThread(10174): setTargetHeapIdealFree:8388608
12-22 14:45:28.482: D/ActivityThread(10174): setTargetHeapConcurrentStart:2097152
12-22 14:45:28.502: D/AndroidRuntime(10174): Shutting down VM
12-22 14:45:28.502: W/dalvikvm(10174): threadid=1: thread exiting with uncaught exception (group=0x4155e438)
12-22 14:45:28.512: E/AndroidRuntime(10174): FATAL EXCEPTION: main
12-22 14:45:28.512: E/AndroidRuntime(10174): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.MYDOMAINAME.www/com.MYDOMAINAME.www.MainActivity}: java.lang.ClassNotFoundException: com.MYDOMAINAME.www.MainActivity
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2012)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.ActivityThread.access$700(ActivityThread.java:139)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.os.Looper.loop(Looper.java:137)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.ActivityThread.main(ActivityThread.java:4918)
12-22 14:45:28.512: E/AndroidRuntime(10174): at java.lang.reflect.Method.invokeNative(Native Method)
12-22 14:45:28.512: E/AndroidRuntime(10174): at java.lang.reflect.Method.invoke(Method.java:511)
12-22 14:45:28.512: E/AndroidRuntime(10174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
12-22 14:45:28.512: E/AndroidRuntime(10174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
12-22 14:45:28.512: E/AndroidRuntime(10174): at dalvik.system.NativeStart.main(Native Method)
12-22 14:45:28.512: E/AndroidRuntime(10174): Caused by: java.lang.ClassNotFoundException: com.MYDOMAINAME.www.MainActivity
12-22 14:45:28.512: E/AndroidRuntime(10174): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-22 14:45:28.512: E/AndroidRuntime(10174): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-22 14:45:28.512: E/AndroidRuntime(10174): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
12-22 14:45:28.512: E/AndroidRuntime(10174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2003)
12-22 14:45:28.512: E/AndroidRuntime(10174): ... 11 more

What did you name your java file for Main? It should be Main.java not MainActivity.java.
If you look at the log , this line 12-22 14:04:16.043: E/AndroidRuntime(9154): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gotonight.www/com.gotonight.www.MainActivity}: java.lang.ClassNotFoundException: com.gotonight.www.MainActivity its trying to find com.gotonight.www.MainActivity but your Main class is com.gotonight.www.Main

Related

Starting with Android Google Maps API V2

I am newbie on Android Google Maps API and I was trying to develop a small app using the API. I use as a reference the Google documentation form: https://developers.google.com/maps/documentation/android/ and I follow all the step with caution. When I build it and install it on to my device (Android 2.3.6) the app crash. I follow all the instructions to sign the app and get the API key for this specific app, tried all the step of the documentation several times without any good results. Please, can someone help me with this? I there something missing?
Thank you!
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.uprm_map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<permission
android:name="com.application.uprm_map.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.application.uprm_map.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.application.uprm_map.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.maps.v2.API_KEY"
android:value="<my own key>"/>
</application>
</manifest>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
MainActivity.java
package com.application.uprm_map;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Exeptions:
03-05 02:29:27.645: D/dalvikvm(32056): GC_EXTERNAL_ALLOC freed 42K, 49% free 2748K/5379K, external 0K/0K, paused 21ms
03-05 02:29:27.650: D/AndroidRuntime(32056): Shutting down VM
03-05 02:29:27.650: W/dalvikvm(32056): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
03-05 02:29:27.655: E/AndroidRuntime(32056): FATAL EXCEPTION: main
03-05 02:29:27.655: E/AndroidRuntime(32056): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.uprm_map/com.application.uprm_map.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.os.Looper.loop(Looper.java:130)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
03-05 02:29:27.655: E/AndroidRuntime(32056): at dalvik.system.NativeStart.main(Native Method)
03-05 02:29:27.655: E/AndroidRuntime(32056): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:234)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.Activity.setContentView(Activity.java:1679)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.application.uprm_map.MainActivity.onCreate(MainActivity.java:11)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-05 02:29:27.655: E/AndroidRuntime(32056): ... 11 more
03-05 02:29:27.655: E/AndroidRuntime(32056): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.application.uprm_map-1.apk]
03-05 02:29:27.655: E/AndroidRuntime(32056): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
03-05 02:29:27.655: E/AndroidRuntime(32056): ... 19 more
03-05 02:29:29.660: I/dalvikvm(32056): threadid=4: reacting to signal 3
03-05 02:29:29.665: I/dalvikvm(32056): Wrote stack traces to '/data/anr/traces.txt'
First thing as you are having the API level 8 or below so you have to use the SupportMapFragment instead of MapFragment as below in your layout file.
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Second thing you have to extend the FragmentActivity instead of Activity :
public class MainActivity extends FragmentActivity {
Do the above changes and then run your application.

Android - ClassNotFoundException after refactoring

I've recently refactored class, package and folder names in my app (it's currently called MyApp) using Eclipse's refactor command, and I'm not getting a ClassNotFoundException. I've made sure there are no more instances of the old name anywhere in the code base. I've also deleted all the class files in \bin\classes and generated Java files in \gen (both of which have regenerated, I've checked). I've also updated the API level from 16 to 17 in an attempt to solve the problem. Here is the stack trace:
12-22 17:00:46.690: E/AndroidRuntime(25466): FATAL EXCEPTION: main
12-22 17:00:46.690: E/AndroidRuntime(25466): java.lang.RuntimeException: Unable to instantiate application com.myapp.MyApp: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyApp" on path: /data/app/com.myapp-2.apk
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.os.Looper.loop(Looper.java:137)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.reflect.Method.invokeNative(Native Method)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.reflect.Method.invoke(Method.java:511)
12-22 17:00:46.690: E/AndroidRuntime(25466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-22 17:00:46.690: E/AndroidRuntime(25466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-22 17:00:46.690: E/AndroidRuntime(25466): at dalvik.system.NativeStart.main(Native Method)
12-22 17:00:46.690: E/AndroidRuntime(25466): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyApp" on path: /data/app/com.myapp-2.apk
12-22 17:00:46.690: E/AndroidRuntime(25466): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-22 17:00:46.690: E/AndroidRuntime(25466): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.Instrumentation.newApplication(Instrumentation.java:968)
12-22 17:00:46.690: E/AndroidRuntime(25466): at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
12-22 17:00:46.690: E/AndroidRuntime(25466): ... 11 more
Here is my Manifest. I know hardcoding strings is bad style.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:name="MyApp"
android:label="MyApp"
android:theme="#style/NoActionBar">
<activity
android:name=".Otheractivity"
android:label="Otheractivity">
</activity>
<activity
android:name=".MainMenu"
android:label="MainMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any ideas on what the problem could be?
had the same problem, solved it by :
right click your project -> Java build path -> order and export(tab) -> make 'v' on "android private libraries"
tell me if it worked.
android:name="MyApp" in your Manifest means you need to have MyApp.java, declaring the class MyApp extending Application in your com.myapp package.
For those who still get this error in Android Studio, I resolved this by deleting .gradle folder from root directory -> clean and build -> run app again.
with the latest version of eclipse/ adt I get this sometimes when I have external libraries included. Removing them from the build path, and re-adding usually works to fix it.

Android - exception launching project on start after copying a lot of code over from another project

am getting this exception:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{business.premium/business.premium.Problemio}:
java.lang.ClassNotFoundException: business.premium.Problemio
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
... 11 more
java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
it says that class is not there, but it IS there. I tried to configure things in my project's build path, but not too sure what to tweak there.
And here is how I start my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="business.premium"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:name="MyApplication"
android:debuggable="true">
<activity
android:name=".Problemio"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any thoughts on how to solve this, or what to look into? Thanks!
Its because you specified the "android:name" attribute in the application node in the manifest file.
Do not use the android:name attribute!
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
This answer is taken from: java.lang.ClassNotFoundException on working app

Sorry the application has stopped unexpectedly android

Can someone please tell me how to fix my problem? I'm building my first android app and below is the error codes I get when application is launched in Emulator.
Thank you
04-12 21:07:03.480: D/AndroidRuntime(327): Shutting down VM
04-12 21:07:03.480: W/dalvikvm(327): threadid=1: thread exiting with uncaught exception(group=0x40015560)
04-12 21:07:03.580: E/AndroidRuntime(327): FATAL EXCEPTION: main
04-12 21:07:03.580: E/AndroidRuntime(327): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{obd.gss.namespace/obd.gss.namespace.activity.Gssobdreadermainactivity}: java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity in loader dalvik.system.PathClassLoader[/data/app/obd.gss.namespace-1.apk]
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.os.Looper.loop(Looper.java:123)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.reflect.Method.invoke(Method.java:507)
04-12 21:07:03.580: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-12 21:07:03.580: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-12 21:07:03.580: E/AndroidRuntime(327): at dalvik.system.NativeStart.main(Native Method)
04-12 21:07:03.580: E/AndroidRuntime(327): Caused by: java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity in loader dalvik.system.PathClassLoader[/data/app/obd.gss.namespace-1.apk]
04-12 21:07:03.580: E/AndroidRuntime(327): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
04-12 21:07:03.580: E/AndroidRuntime(327): ... 11 more
Here are the contents of my manifest:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Activity.Gssobdreadermainactivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity.Gssobdreaderconfigactivity"
android:label="#string/app_name">
</activity>
<activity android:name=".activity.Gssobdreadercommandactivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<service android:name="io.GssobdReaderService"/>
</application>
The cause of your problem is:
java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity
Did you forget to add your Activity to your manifest?
Your Manifest should look something like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="obd.gss.namespace"
android:versionCode="1"
android:versionName="1.0" >
<!-- permissions and other stuff here -->
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".activity.Gssobdreadermainactivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--more activities and services here -->
</application>
</manifest>
Note that the combination of the manifest tag's package attribute and the activity tag's name attribute should be exactly the same as the fully qualified name of your class. Using my above example, you would wind up with:
obd.gss.namespace.activity.Gssobdreadermainactivity
I've had a similar issue, particularly with newly imported projects. The closest thing to a solution I've found is to make sure the .classpath file is writable, restart Eclipse(or whichever IDE you use), refresh the project, clean and build the project and try again. This doesn't always fix it, but doing it a couple times usually makes the error go away for me. The essence of the error is that the Android OS can't find the Activity, although it does know that the Activity should exist and is trying to launch it.
What does your source tree look like? You probably need to remove the .activity. and .Activity. prefixes from your applications fully quallified class name. Unless, of course, you have an "activity" and an "Activity" folder in your source tree (=

ClassNotFoundException on Galaxy Tab (only)

I have a working Android application. It works on more than 500 different devices. The manifest is
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.decamps.droid.photoid" android:versionCode="5"
android:versionName="1.4">
<application android:icon="#drawable/icon" android:label="#string/app_label"
android:name="PhotoIDroid" android:description="#string/app_desc"
android:debuggable="FALSE">
But when it it launched from a Samsung Galaxy Tab, it doesn't start and crashes with:
java.lang.RuntimeException: Unable to
instantiate application
info.decamps.droid.photoid.PhotoIDroid:
java.lang.ClassNotFoundException:
info.decamps.droid.photoid.PhotoIDroid
in loader
dalvik.system.PathClassLoader[/data/app/info.decamps.droid.photoid-1.apk]
at
android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:670)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4483)
at
android.app.ActivityThread.access$3000(ActivityThread.java:135)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2181)
at
android.os.Handler.dispatchMessage(Handler.java:99)
at
android.os.Looper.loop(Looper.java:144)
at
android.app.ActivityThread.main(ActivityThread.java:4937)
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:868)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at
dalvik.system.NativeStart.main(Native
Method) Caused by:
java.lang.ClassNotFoundException:
info.decamps.droid.photoid.PhotoIDroid
in loader
dalvik.system.PathClassLoader[/data/app/info.decamps.droid.photoid-1.apk]
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.newApplication(Instrumentation.java:945)
at
android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:660)
... 11 more
How an the Samsung Galaxy not find the application class?
Any clue on how to resolve this?
I have been able to reproduce tis crash on the Samsung Galaxy emulator.
I have removed the android:name attribute declaration from the AndroidManifest.xml and it now works.

Categories

Resources