Starting a service crashed the Android emulator - android

I have a quite vanilla service that works seamlessly when the app is executed on my LG device. Yet when I do it on the Eclipse emulator for the Nexus 5 I get a crash, leaving me with the suspect this behavior could also emerge on real devices different from mine. This is the code:
Intent startBackgroundLocationIntent= new Intent(this, BackgroundLocationService.class);
startService(startBackgroundLocationIntent);
and the crash log:
08-13 14:18:10.731: E/AndroidRuntime(6345): FATAL EXCEPTION: main
08-13 14:18:10.731: E/AndroidRuntime(6345): Process:
com.example.taxiprofessional, PID: 6345 08-13 14:18:10.731:
E/AndroidRuntime(6345): java.lang.RuntimeException: Unable to start
service
com.example.taxiprofessional.BackgroundLocationService#b20e39b0 with
Intent { cmp=com.example.taxiprofessional/.BackgroundLocationService
}: java.lang.NullPointerException 08-13 14:18:10.731:
E/AndroidRuntime(6345): at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2719)
08-13 14:18:10.731: E/AndroidRuntime(6345): at
android.app.ActivityThread.access$2100(ActivityThread.java:135) 08-13
14:18:10.731: E/AndroidRuntime(6345): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
08-13 14:18:10.731: E/AndroidRuntime(6345): at
android.os.Handler.dispatchMessage(Handler.java:102) 08-13
14:18:10.731: E/AndroidRuntime(6345): at
android.os.Looper.loop(Looper.java:136) 08-13 14:18:10.731:
E/AndroidRuntime(6345): at
android.app.ActivityThread.main(ActivityThread.java:5017) 08-13
14:18:10.731: E/AndroidRuntime(6345): at
java.lang.reflect.Method.invokeNative(Native Method) 08-13
14:18:10.731: E/AndroidRuntime(6345): at
java.lang.reflect.Method.invoke(Method.java:515) 08-13 14:18:10.731:
E/AndroidRuntime(6345): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-13 14:18:10.731: E/AndroidRuntime(6345): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 08-13
14:18:10.731: E/AndroidRuntime(6345): at
dalvik.system.NativeStart.main(Native Method) 08-13 14:18:10.731:
E/AndroidRuntime(6345): Caused by: java.lang.NullPointerException
08-13 14:18:10.731: E/AndroidRuntime(6345): at
com.example.taxiprofessional.BackgroundLocationService.uploadCoordinatesForLocation(BackgroundLocationService.java:100)
08-13 14:18:10.731: E/AndroidRuntime(6345): at
com.example.taxiprofessional.BackgroundLocationService.onStartCommand(BackgroundLocationService.java:138)
08-13 14:18:10.731: E/AndroidRuntime(6345): at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2702)
08-13 14:18:10.731: E/AndroidRuntime(6345): ... 10 more

Reading that stack trace, it looks like the code that's crashing is your upload method:
E/AndroidRuntime(6345): Caused by: java.lang.NullPointerException 08-13 14:18:10.731: E/AndroidRuntime(6345): at com.example.taxiprofessional.BackgroundLocationService.uploadCoordinatesForLocation(BackgroundLocationService.java:100)
Just speculating here, but have you validated that you're null checking the coordinates that you're trying to upload? Your emulator won't have a location unless you configure mock locations correctly.

I fixed the whole issue by checking if variable last was null before calling the function and by requesting the best provider; this is the code snippet I hope to be of use for beginners like me:
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(criteria, true);
if (lm!=null) {
Location last=lm.getLastKnownLocation(provider);
if (last!=null) uploadCoordinatesForLocation(last);
lm.requestLocationUpdates(provider, 0, 0, locationListener);
}
Thanks everyone.

Related

Get error when back to the previous activity in intent

In My app When I go to the settings activity then back, my app force to stop the activity, I don't know which mistake is there.Please help me to solve that. Thanks for your help in advance!
08-13 11:36:36.355 21968-21968/com.example.user.dictationapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.dictationapp, PID: 21968
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.dictationapp/com.example.user.dictationapp.DictationVocab}: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
at android.widget.CompoundButton.onRestoreInstanceState(CompoundButton.java:378)
at android.view.View.dispatchRestoreInstanceState(View.java:12842)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2658)
at android.view.View.restoreHierarchyState(View.java:12820)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1874)
at android.app.Activity.onRestoreInstanceState(Activity.java:949)
at android.app.Activity.performRestoreInstanceState(Activity.java:921)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
Having experienced these ClassCastExceptions before, I'd suggest that you check that you do not have a same id being shared by different widgets. Also, check with layouts in different layout-qualifiers folders for the same condition.

Fabric crash at startup

My app crashed at this line inside onCreate() function
Fabric.with(this, new Crashlytics());
The device is SAMSUNG SM-G313 HZ, running 4.4.2
I've reported to their Twitter dev forum, but my post is automarked as spam.
Anybody knows a workaround?
This is the onCreate function:
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
graph = ObjectGraph.create(getModules());
ImageLoaderConfiguration imageLoaderConfiguration =
ImageLoaderConfiguration.
createDefault(getApplicationContext());
ImageLoader.getInstance().init(imageLoaderConfiguration);
MMX.init(this, R.raw.initfile);
MMX.registerListener(new MessageEventListenerForLockScreen(this));
Intent intent = new Intent(getString(R.string.wake_up_key));
MMX.registerWakeupBroadcast(intent);
}
I've already declared fabric in AndroidManifest
<meta-data
android:name="io.fabric.ApiKey"
android:value="mykeyhere_a1cff923b11afaab1be7b005474d99b912b3"/>
Logcat:
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: FATAL EXCEPTION: main
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: Process: funride.android.com.rideshare, PID: 16717
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: java.lang.VerifyError: com/crashlytics/android/core/CrashlyticsCore
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:29)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at funride.android.com.rideshare.application.CloudBikeApp.onCreate(CloudBikeApp.java:33)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4593)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:151)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:110)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.os.Looper.loop(Looper.java:193)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5344)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:676)
10-06 13:31:53.452 16717-16717/funride.android.com.rideshare E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
It may be a conflict with third-party libraries, I had a similar crash when using Retrofit2, because Fabric uses an older version of Retrofit.
It may be that you are using the retrofit 2.0 beta?
Twitter currently uses retrofit 1.8 and won't update until the final release of retrofit 2.0
Discussion that will hopefully be updated when it's fixed can be found here: https://twittercommunity.com/t/java-lang-verifyerror/53974

Android app running on Emulator but not on device_getting stackoverflow error

When I am trying to open a tabactivity it is running fine on emulator but not on real device.
the min and max sdk in manifet file as shown
android:minSdkVersion="8"
android:targetSdkVersion="17"
And my device is samsung tablet having 4.1.1 version
08-13 17:53:42.034: E/AndroidRuntime(22602): FATAL EXCEPTION: main
08-13 17:53:42.034: E/AndroidRuntime(22602): java.lang.StackOverflowError
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.content.res.Resources.obtainAttributes(Resources.java:1393)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:117)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.content.res.Resources.loadDrawable(Resources.java:1948)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.content.res.Resources.getDrawable(Resources.java:672)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
08-13 17:53:42.034: E/AndroidRuntime(22602): at android.content.res.Resources
TabActivity was deprecated in API 13, so it is not guaranteed to work correctly on Android 3.2 or later. Consider using Fragments instead.
Stack overflow errors typically happen when a recursive function doesn't have a proper base case. In other words, the recursive function will keep calling itself, thus adding it's variables onto the stack until the stack space is gone. If you are using any recursive functions, be sure you have a proper base case. If you aren't using any recursive functions, something probably went wrong in the deprecated TabActivity class.

Phonegap Android facebook plugin crashes

I am getting the error below when I try to login through facebook plugin for Android.
The app basically crashes "stopped", Any ideas will be appreciated.
ERROR/AndroidRuntime(2008): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {xxx/com.facebook.LoginActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x7f060012
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f060012
at android.content.res.Resources.getText(Resources.java:230)
at android.content.res.Resources.getString(Resources.java:314)
at android.content.Context.getString(Context.java:327)
at com.facebook.widget.WebDialog.onCreate(WebDialog.java:189)
at android.app.Dialog.dispatchOnCreate(Dialog.java:355)
at android.app.Dialog.show(Dialog.java:260)
at com.facebook.AuthorizationClient$WebViewAuthHandler.tryAuthorize(AuthorizationClient.java:471)
at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:214)
at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:193)
at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:121)
at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:102)
at com.facebook.LoginActivity.onResume(LoginActivity.java:113)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
at android.app.Activity.performResume(Activity.java:5182)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
... 12 more
i kinda resolved it, i deleted the app_id string. turns out facebook plugin doesn't use that.

Application crashes onResume in ICS while working perfect on Gingerbread

My main Activity (say A) raises intent to fetch a ContactID from ContactsContract through
startActivityForResult(new Intent(Intent.ACTION_PICK, contactsContract.Contacts.CONTENT_URI),PICK_CONTACT);
While returning (onActivityResult(int reqCode, int resultCode, Intent data)), I am using details from 'data' to query the contacts through
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
......
my code works fine with Android 2.x. However this code gets crashed in ICS (Android 4.x), while resuming the main Activity(A).
I am not sure, whether it is due to the deprecated 'managedQuery'.
Can somebody offer some solution, I am stuck and unable to even find which line causes the error as the Log cat is not showing even the error line number. it simply says
Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
Thanks in advance
Joshy
I have tried the above code just after completing the requirement of the cursor. Still the problem persists. My Log cat says as follows
08-13 00:26:31.427: W/dalvikvm(3176): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-13 00:26:31.447: E/AndroidRuntime(3176): FATAL EXCEPTION: main
08-13 00:26:31.447: E/AndroidRuntime(3176): java.lang.RuntimeException: Unable to resume activity {com.desquare.sp/com.desquare.sp.SmartPadActivity}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.os.Looper.loop(Looper.java:137)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-13 00:26:31.447: E/AndroidRuntime(3176): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 00:26:31.447: E/AndroidRuntime(3176): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 00:26:31.447: E/AndroidRuntime(3176): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-13 00:26:31.447: E/AndroidRuntime(3176): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-13 00:26:31.447: E/AndroidRuntime(3176): at dalvik.system.NativeStart.main(Native Method)
08-13 00:26:31.447: E/AndroidRuntime(3176): Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:75)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:144)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.database.CursorWrapper.requery(CursorWrapper.java:186)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.Activity.performRestart(Activity.java:4505)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.Activity.performResume(Activity.java:4531)
08-13 00:26:31.447: E/AndroidRuntime(3176): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
08-13 00:26:31.447: E/AndroidRuntime(3176): ... 10 more
It sounds like this is the problem:
*
android.database.staledataexception : Access closed cursor
You seem to be getting the cursors using managedQuery.
I had problems with restoring an application, which for some reason in
Icecream Sandwich did not close the cursors properly. The fix was to
do this for all cursors right after using them:
if (cursor != null && !cursor.isClosed()) {
myActivity.stopManagingCursor( cursor );
cursor.close();
}
The API startManagingCursor/stopManagingCursor is deprecated and is the root cause of the issue.
For example, please comment this out and verify.

Categories

Resources