My app crashes in some devices when try to open an Activity. The problem does not always occur, only on some devices.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.pickerManager = GlobalHolder.getInstance().getPickerManager();
this.pickerManager.setActivity(TempActivity.this); // <== line with error
this.pickerManager.pickPhotoWithPermission();
}
Stacktrace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chillihaze.deskeep/com.libraries.imagepicker.TempActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.libraries.imagepicker.e.a(android.app.Activity)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.libraries.imagepicker.e.a(android.app.Activity)' on a null object reference
at com.libraries.imagepicker.TempActivity.onCreate(SourceFile:3)
at android.app.Activity.performCreate(Activity.java:7148)
at android.app.Activity.performCreate(Activity.java:7139)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1293)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
I can't reproduce the error on my devices, so I can't test it.
I can't reproduce the error on my devices, so I can't test it.
Ah, you can reproduce the error on all Android devices, you just need to know how ;)
After low memory condition happens, only the current Activity gets recreated at first, previous Activity is recreated on back navigation, and all static variables are nulled out (because the process is technically restarted).
Way to reproduce:
Go to TempActivity in your app
put your application in background with HOME button
click the TERMINATE button in Android Studio
re-launch the app from the launcher
You'll experience this phenomenon.
(In AS 4.0 Canary, this won't work, and instead of using the terminate button, you'd need to use terminal command adb shell am kill your.package.name)
The solution is to use statics with the knowledge and caution that the MAIN activity (the one you defined with <intent-filter>'s MAIN action) is NOT guaranteed to run AT ALL during an Android app's execution, so you should be initializing stuff accordingly.
You can easily return to a DETAIL screen as your First Starting Activity in your app, and the LIST screen would be created only on back navigation.
Also you can check out intent.putExtra( and getIntent() methods which are kept across process death / low memory condition by Android System.
Make sure that the this.pickerManager is not null, on the following line
this.pickerManager.setActivity(TempActivity.this)
Related
I have received a pre-launch report on my play.google.com/console:
Android 8.1 (SDK 27)
FATAL EXCEPTION: UIAsyncWorker
Process: com.google.android.music:main, PID: 11466
java.lang.RuntimeException: Attempt to invoke interface method 'boolean com.google.android.finsky.services.IMarketCatalogService.isBackendEnabled(java.lang.String, int)' on a null object reference
at com.google.android.music.utils.async.CallerTracker.reThrowExceptionWithCallerStackTrack(CallerTracker.java:32)
at com.google.android.music.utils.async.TraceableRunnable.runLogged(TraceableRunnable.java:23)
at com.google.android.music.utils.async.LoggedRunnable.run(LoggedRunnable.java:30)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.music.utils.LoggableHandler.dispatchMessage(LoggableHandler.java:74)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.google.android.finsky.services.IMarketCatalogService.isBackendEnabled(java.lang.String, int)' on a null object reference
at com.google.android.music.tutorial.SignupStatus.checkStoreAvailable(SignupStatus.java:216)
at com.google.android.music.tutorial.SignupStatus.doCheck(SignupStatus.java:154)
at com.google.android.music.tutorial.SignupStatus.launchVerificationCheck(SignupStatus.java:129)
at com.google.android.music.tutorial.SignupStatus.launchVerificationCheckWithFallbackTask(SignupStatus.java:113)
at com.google.android.music.AccountsBroadcastReceiver$1.run(AccountsBroadcastReceiver.java:30)
at com.google.android.music.utils.async.TraceableRunnable.runLogged(TraceableRunnable.java:21)
... 6 more
com.google.android.music - is not my application.
Can I fix the issue or it is a problem in the android device and not in my code?
I'm also seeing this now, in addition to another similar bug affecting a lot of users. It appears to be yet another bug in the Pre-launch reports and not related to our code. My app doesn't use sound, let alone Android Music.
Those affected, please consider reporting it on this bug report.
Since a few days ago and out of nowhere, I sometimes get this NullPointException error:
Exception: java.lang.NullPointerException - Attempt to invoke virtual
method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null
object reference 03-19 09:08:47.785 22799-22820/? W/System.err:
java.lang.NullPointerException: Attempt to invoke virtual method
'boolean java.util.ArrayList.add(java.lang.Object)' on a null object
reference
at com.codename1.r.an.cj(TextArea.java:1199)
at com.codename1.r.an.ci(TextArea.java:865)
at com.codename1.r.an.H(TextArea.java:879)
at com.codename1.r.an.F(TextArea.java:824)
at com.codename1.r.g.b.a(DefaultLookAndFeel.java:907)
at com.codename1.r.an.a(TextArea.java:1259)
at com.codename1.r.l.J(Component.java:2942)
at com.codename1.r.l.K(Component.java:2981)
at com.codename1.r.l.aa(Component.java:1340)
at com.codename1.r.l.af(Component.java:1430) 03-19 09:08:47.786 22799-22820/? W/System.err: at
com.codename1.r.e.a.b(BorderLayout.java:480)
at com.codename1.r.n.a(Container.java:2224)
at com.codename1.r.l.J(Component.java:2942)
at com.codename1.r.l.K(Component.java:2981)
at com.codename1.r.l.aa(Component.java:1340)
at com.codename1.r.l.af(Component.java:1430)
at com.codename1.r.e.b.a(BoxLayout.java:155)
at com.codename1.r.n.bP(Container.java:1715)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.bP(Container.java:1720)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.bP(Container.java:1720)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.bP(Container.java:1720)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.a(Container.java:1606)
at com.codename1.r.v.a(Form.java:4046)
at com.codename1.r.l.b(Component.java:2214)
at com.codename1.r.v.b(Form.java:4056)
at com.codename1.r.l.d(Component.java:2187)
at com.codename1.r.l.a(Component.java:2162) 03-19 09:08:47.787 22799-22820/? W/System.err: at
com.codename1.r.l.d(Component.java:2130)
at com.codename1.r.l.c(Component.java:2421)
at com.codename1.r.l.i(Component.java:2365)
at com.codename1.impl.a.s(CodenameOneImplementation.java:613)
at com.codename1.r.q.l(Display.java:1161)
at com.codename1.r.q.k(Display.java:1070)
at com.codename1.r.aj.run(RunnableWrapper.java:120)
at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:776)
It doesn't come from my code and I have no idea how to resolve this intermittent error.
Please help me!
Most of these issues occur due to race conditions and violations of the EDT. This means you made changes to the UI in a separate thread either manually created or obtained via: timer, network etc.
We provide an EDT violation detection tool in the simulator which you can enable. As you run with this tool enabled it will print the stack traces for suspected violations. Notice that in some cases it can produce "false positives" but it's normally pretty good at such cases.
Updated
TextArea is an UI component so all interaction should happen on the codenameOne event dispatch thread (EDT).
In the codenameone master file for TextArea, the variable rowText is declared inside the method and has a call prior, so it's not null. So the culprit appears to be rowStrings.add(rowText).
The stack trace is reported at:
https://github.com/codenameone/CodenameOne/blob/master/CodenameOne/src/com/codename1/ui/TextArea.java#L1199
rowStrings is an instance member, but it's not final or protected with locking.
Shai Almog points out in his answer: any manipulation of TextArea should happen on the EDT. TextArea as a UI component should not need to worry about concurrency.
All of sudden my app crashes in between smooth sailing.
Complete error:
at android.view.ViewRootImpl.setView(ViewRootImpl.java:679)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.widget.Toast$TN.handleShow(Toast.java:434)
at android.widget.Toast$TN$2.handleMessage(Toast.java:345)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
I am finding it very hard to debug . Please throw some light on how to debug it .Thanks for the help.
IMPORTANT NOTE
This is not a duplicate of
Error : BinderProxy#45d459c0 is not valid; is your activity running?.
I am not using any dialog in my app . Yes i am indeed using simple
Toasts . But its not clear whats causing the error....
UPDATE:This error is happening the activity that has TabbedLayout.I have removed all toasts,the error still persists.I have used Logs instead
This exception comes when trying to perform operation on main thread while thread does not exist. This happens when you are showing dialog in a activity/fragments but that class is already finished, so this exception come.
To handle this exception while showing any types of dialog check the isFinishing() status.
There might be context would be old window (Activity) where Activity configuration might be change and you may preserve old context which has no any window available right now.
That's why this could be occurred.
Please check your code is there any configuration change or Activity get refresh?
And your Toast class inside you are giving closed window or old window context which is not actually present.
I've been working on a single activity application that receives UDP packets, parses their message, then changes an ImageView, a TextView, and plays an alert song depending on what the message contains. I have three classes: MainActivity, ListeningService, and AndroidUDP. MainActivity contains all of the GUI implentation, AndroidUDP contains the enumeration that contains the 20 possible alert types dependent on what the UDP message contains as well as sets the TextView and ImageViews, and ListeningService contains the AsyncTask private class.
I didn't write this, an electrical engineer did and I was tasked with making it actually work. When I attempt to call the ListeningService via the AndroidUDP.startIt() method I get the error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.p3_group.v2vapp/com.p3_group.v2vapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.p3_group.v2vapp.ListeningService.continueListening()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.p3_group.v2vapp.ListeningService.continueListening()' on a null object reference
at com.p3_group.v2vapp.MainActivity.onCreate(MainActivity.java:61)
I'm sure that I'm doing something dumb like trying to call the background update from the wrong thread. I've never done this kind of thing before so any pointers would be great!
and yes, i know this code is pretty bad. I only need it functional for what we're doing, not perfect
Hi you didn't start the service at all and you are trying to bind the service in "public void doStuff(MainActivity r, IntentFilter filter)" but it will not bind, so ListeningService listeningService is null in AndroidUDP, but you are trying to call below method, but listeningService is null so it's giving null pointer exception.
public void startIt()
{
listeningService.continueListening();
}
I am getting this error log on crashlytics. I don't know what makes this crash.
It occurs on Android 4.x, 5.x, 6.x devices. (Samsung, Sony, LGE etc.)
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference
at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
at android.view.inputmethod.InputMethodManager.checkFocusNoStartInput(InputMethodManager.java:1809)
at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1761)
at android.view.inputmethod.InputMethodManager.isActive(InputMethodManager.java:883)
at android.widget.Editor$CursorAnchorInfoNotifier.updatePosition(Editor.java:4095)
at android.widget.Editor$PositionListener.onPreDraw(Editor.java:2564)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1018)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2313)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1301)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7021)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6918)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
As mentioned here, this can happen because of the Android Advanced Profiling tool.
Disable it from the Run/Debug Configurations dialog:
Make sure the input connection is not null in your onCreateInputConnection override method.
#Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
if (inputConnection == null)
{
return null;
}
return new MyInputConnectionWrapper(inputConnection,
true);
}
Where MyInputConnectionWrapper is your custom input connection wrapper which is extended from InputConnectionWrapper.
It also happened to me because of Advanced Profiling option is enabled.
To disable the advanced profiling, follow these steps:
Select Run > Edit Configurations.
Select your app module in the left pane.
Click the Profiling tab, and then uncheck Enable advanced profiling.
Learn more
The above answer should be correct, but in my scenario, the reason for this error is:
Edittext is having focus, and this error occurs when edittext.getText() is used.
To avoid this error you must:
edittext.gettext().toString();
Note: This edittext must have focus to make this error.
Assume the fragment or Activity have a non EditTextView named mTv; At some appropriate time,mTv.requestFocuse(); This works for me. Hope this helps you.