I got a ANR report on firebase. Its count is increasing and I cannot figure out this since it does not mention anywhere on my code. This is the ANR on firebase console.
main (native): tid=1 systid=5789
at libcore.io.Linux.access(Linux.java)
at libcore.io.ForwardingOs.access(ForwardingOs.java:72)
at libcore.io.BlockGuardOs.access(BlockGuardOs.java:73)
at libcore.io.ForwardingOs.access(ForwardingOs.java:72)
at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:7766)
at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:281)
at java.io.File.exists(File.java:815)
at android.app.ContextImpl.ensureExternalDirsExistOrFilter(ContextImpl.java:2889)
at android.app.ContextImpl.getExternalFilesDirs(ContextImpl.java:773)
at android.content.ContextWrapper.getExternalFilesDirs(ContextWrapper.java:289)
at androidx.core.content.ContextCompat$Api19Impl.getExternalFilesDirs(ContextCompat.java:847)
at androidx.core.content.ContextCompat.getExternalFilesDirs(ContextCompat.java:409)
at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:691)
at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:635)
at androidx.core.content.FileProvider.attachInfo(FileProvider.java:416)
at android.app.ActivityThread.installProvider(ActivityThread.java:7471)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6950)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6845)
at android.app.ActivityThread.access$1400(ActivityThread.java:244)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1959)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7889)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Any idea how to get rid of this ANR?
Related
I am making a chat app and want to implement a feature to get the online-offline and typing statuses for that in my adapter. I am trying to get the value from the database to display.
This is what I tried
FirebaseFirestore database = FirebaseFirestore.getInstance();
Log.d("conversationId",chatMessage.conversationId + "");
database.collection(Constants.KEY_COLLECTION_USERS)
.document(chatMessage.conversationId + "")
.addSnapshotListener((value, error) -> {
if (value.getString(Constants.KEY_AVAILABILITY).equals("0")){
binding.onlineIndicator.setVisibility(View.GONE);
binding.textRecentConversation.setText(chatMessage.message);
}else if (value.getString(Constants.KEY_AVAILABILITY).equals("1")){
binding.onlineIndicator.setVisibility(View.VISIBLE);
binding.textRecentConversation.setText(chatMessage.message);
}else if (value.getString(Constants.KEY_AVAILABILITY).equals("2")){
makeTypingText(binding, chatMessage.conversationName);
binding.onlineIndicator.setVisibility(View.VISIBLE);
}
});
And this is the error I got
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chatverse.free, PID: 14452
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.chatverse.free.Adapters.RecentConversationsAdapter$ConversationViewHolder.lambda$setData$0$com-chatverse-free-Adapters-RecentConversationsAdapter$ConversationViewHolder(RecentConversationsAdapter.java:144)
at com.chatverse.free.Adapters.RecentConversationsAdapter$ConversationViewHolder$$ExternalSyntheticLambda3.onEvent(Unknown Source:6)
at com.google.firebase.firestore.DocumentReference.lambda$addSnapshotListenerInternal$2$com-google-firebase-firestore-DocumentReference(DocumentReference.java:504)
at com.google.firebase.firestore.DocumentReference$$ExternalSyntheticLambda2.onEvent(Unknown Source:6)
at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0$com-google-firebase-firestore-core-AsyncEventListener(AsyncEventListener.java:42)
at com.google.firebase.firestore.core.AsyncEventListener$$ExternalSyntheticLambda0.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
This is how I verified
First, in the logs, I check the value I printed for the receiver id. It's correct.
I also verified the keys, and everything is correct. I am not sure why such an error is occurring.
I got it.
I was using a static String, giving n error, but it worked when I tried using hard-coded values. Note that this gave me an emulator error but worked fine with an actual device! To make it work on an emulator, I had to try/catch for NullPointerExeption.
Thanks to #AlexMamo
I have an android app that has a second module included in the app when the main activity starts an activity in the module everything is good. The problem is if you go to another app and then resume this app the activity crashes with a null object pointer. My app uses Esri ArcGIS runtime SDK. I have a MapView open in the activity when the crash occurs. I don't have any problem with an open map in the MainActivity and the app goes to the background then back to the current app.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.thevillages.myfirstapp, PID: 23267
java.lang.RuntimeException: Unable to resume activity {com.thevillages.myfirstapp/com.thevillages.maplib.MapNavActivity}: com.esri.arcgisruntime.ArcGISRuntimeException: Null pointer.: object cannot be null.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4205)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: com.esri.arcgisruntime.ArcGISRuntimeException: Null pointer.: object cannot be null.
at com.esri.arcgisruntime.internal.jni.CoreGeoView.nativeResume(Native Method)
at com.esri.arcgisruntime.internal.jni.CoreGeoView.b(SourceFile:5)
at com.esri.arcgisruntime.a.i.f.g.d(SourceFile:3)
at com.esri.arcgisruntime.mapping.view.GeoView$RenderingThread.resume(SourceFile:4)
at com.esri.arcgisruntime.mapping.view.MapView.resume(SourceFile:1)
at com.thevillages.maplib.MapNavActivity.onResume(MapNavActivity.java:816)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
at android.app.Activity.performResume(Activity.java:7939)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I systematically went through my onCreate() method and added each piece of the code to find where the problem was. I found some code that was suspicious and I could not recall why I added the code. With the code removed the app works fine.
My application is facing random crashes for real users. Unfortunately I can not reproduce it. Has any one has more insight on the issue, or have a solution for the crash? The stack trace is as follows.
java.lang.IllegalArgumentException: path must be convex
at android.graphics.Outline.setConvexPath(Outline.java:284)
at android.graphics.drawable.GradientDrawable.getOutline(GradientDrawable.java:1745)
at android.view.ViewOutlineProvider$1.getOutline(ViewOutlineProvider.java:38)
at android.view.View.rebuildOutline(View.java:17362)
at android.view.View.invalidateDrawable(View.java:22675)
at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:457)
at android.graphics.drawable.Drawable.setVisible(Drawable.java:866)
at android.view.View.onVisibilityAggregated(View.java:13928)
at android.view.View.dispatchDetachedFromWindow(View.java:20062)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3995)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3987)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3987)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5588)
at android.view.ViewGroup.removeViewAt(ViewGroup.java:5535)
at android.support.v7.widget.RecyclerView$5.removeViewAt(RecyclerView.java:877)
at android.support.v7.widget.ChildHelper.removeViewAt(ChildHelper.java:168)
at android.support.v7.widget.RecyclerView$LayoutManager.removeViewAt(RecyclerView.java:8374)
at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleViewAt(RecyclerView.java:8647)
at android.support.v7.widget.LinearLayoutManager.recycleChildren(LinearLayoutManager.java:1369)
at android.support.v7.widget.LinearLayoutManager.recycleViewsFromEnd(LinearLayoutManager.java:1449)
at android.support.v7.widget.LinearLayoutManager.recycleByLayoutState(LinearLayoutManager.java:1482)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1508)
at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1331)
at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1075)
at android.support.v7.widget.RecyclerView.scrollStep(RecyclerView.java:1832)
at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5067)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
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:965)
I found this stackoverflow post but it is not useful in my case. The issue appears to be happening while drawing RecyclerView. I use custom background for RecyclerView items which I suspect might be the reason.
So, I have been following a YouTube tutorial for an android Weather application. The app seems to compile, however crashes whenever opened on the emulator. I'm not the most fluent programmer, however the code is understood. I can't figure out what's causing the issue though. The app is supposed to fetch weather data for the location of the hardcoded location in "MainActivity.java". The data is fetched from Yahoo! using an API.
Link for the project files: https://drive.google.com/drive/folders/0B2dQ9-JQjysVeXlqZENBZDExN0E?usp=sharing
Below is the error I get:
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mattbenson.cw_2_weather, PID: 2529
java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
at com.example.mattbenson.cw_2_weather.service.WeatherService$1.onPostExecute(WeatherService.java:81)
at com.example.mattbenson.cw_2_weather.service.WeatherService$1.onPostExecute(WeatherService.java:38)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
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)
E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19
E/EGL_emulation: tid 2570: swapBuffers(487): error 0x300d (EGL_BAD_SURFACE)
W/OpenGLRenderer: swapBuffers encountered EGL error 12301 on 0x76990bb1c580, halting rendering...
Application terminated.
(Sorry, I am new to this site!)
Any help is greatly appreciated.
As StackTrace says the error is at Class WeatherService at line 81 int count = queryResults.optInt("Count"); because it is returning NULL.
Try using method optInt with fallback value queryResults.optInt("Count", 0);
In our Android mobile application (compatible with Android versions 4.0 and upper), we use Google Maps API V2.
We get some bug reports from users on some kinds of devices (Android versions 4.3, 4.4 and 5.0) with a NullPointerException in setBoundsInParent method of android.view.accessibility.AccessibilityNodeInfo class.
The application crashes when the user tries to move or to zoom on the map.
The problem only appears for some users - devices. Most of our customers do not have that problem.
The problem seems to come from the use of the setPadding method of Google Maps API to position the Google logo so that it is always clearly visible on the map :
#Override
protected void onCreate(Bundle savedInstanceState)
{
...
// Initialize map
...
// Sets the padding for the map
if(mMap!=null)
{
mMap.setPadding(0, DPI.toPixels(100), 0, DPI.toPixels(100));
}
...
}
Removing the call to the setPadding method seems to resolve the problem for affected users but it is not a valid solution for us because we need to position the Google logo with this method.
We cannot reproduce this problem on our development devices, so it's difficult for us to find the real origin of this problem.
You will find the full stacktraces of the bug below.
Does someone have an idea?
Thanks a lot in advance for your answer.
Best regards.
Stacktrace on Android 4.3 - 4.4
java.lang.NullPointerException
at android.view.accessibility.AccessibilityNodeInfo.setBoundsInParent(AccessibilityNodeInfo.java:1012)
at android.support.v4.view.a.k.c(SourceFile:819)
at android.support.v4.view.a.i.b(SourceFile:1850)
at com.google.maps.api.android.lib6.c.et.a(Unknown Source)
at android.support.v4.widget.ab.a(SourceFile:56)
at android.support.v4.widget.ac.a(SourceFile:717)
at android.support.v4.view.a.x.a(SourceFile:112)
at android.support.v4.view.a.ad.createAccessibilityNodeInfo(SourceFile:42)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:724)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:147)
at android.view.AccessibilityInteractionController.access$300(AccessibilityInteractionController.java:49)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:971)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5212)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Stacktrace on Android 5.0
java.lang.NullPointerException: Attempt to read from field 'int android.graphics.Rect.left' on a null object reference
at android.view.accessibility.AccessibilityNodeInfo.setBoundsInParent(AccessibilityNodeInfo.java:1316)
at android.support.v4.view.a.k.c(SourceFile:819)
at android.support.v4.view.a.i.b(SourceFile:1850)
at com.google.maps.api.android.lib6.c.et.a(Unknown Source)
at android.support.v4.widget.ab.a(SourceFile:56)
at android.support.v4.widget.ac.a(SourceFile:717)
at android.support.v4.view.a.x.a(SourceFile:112)
at android.support.v4.view.a.ad.createAccessibilityNodeInfo(SourceFile:42)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:894)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:155)
at android.view.AccessibilityInteractionController.access$400(AccessibilityInteractionController.java:53)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
The bug has been confirmed by Google : http://code.google.com/p/gmaps-api-issues/issues/detail?id=7619
Best regards.