This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am new to Android programming
and I try to learn it and take sample sample applications on the git * ub site, I have tried to resolve some errors in the application and after compiling the application is able to run, but the problem that arises when I open the details from the application post, the error is like this
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.newsagni/com.app.newsagni.ActivityPostDetails}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2550)
at android.app.ActivityThread.access$1100(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5615)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.app.newsagni.ActivityPostDetails.displayPostData(ActivityPostDetails.java:190)
at com.app.newsagni.ActivityPostDetails.onCreate(ActivityPostDetails.java:98)
at android.app.Activity.performCreate(Activity.java:6362)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2443)
... 9 more
The following listings from
ActivityPostDetails.java
https://pastebin.com/h56LUx2T
activity_post_details.xml
https://pastebin.com/hwYpza37
Can you help me overcome this error
You don't have a TextView with an id of "date", so Android cannot find the TextView. Therefore you get a NPE when trying to work with it. Add the TextView to your activity and you should be good to go.
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
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 1 year ago.
2021-08-14 19:43:53.129 8682-8682/com.future.vpn E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.future.vpn, PID: 8682
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.future.vpn.Activities.MainActivity.onStart(MainActivity.java:186)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1435)
at android.app.Activity.performStart(Activity.java:8024)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3475)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
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)
2021-08-14 19:43:53.186 8682-8682/com.future.vpn I/Process: Sending signal. PID: 8682 SIG: 9
In onstart() Method you have a string that is not initialized and you are comparing it with another string that's why you are getting this error.
first, initialize string then compare with another string
This is a NullPointerException, you are passing a null value. Place break points on the sections that contain variables/values then run it (using the Debug feature on). This will show you:
which value you are getting a null response from. Once achieved, now check:
how your code structure is (global and local scopes). This might be an issue as the scope of the variable assignment determines whether your variable has a value or it doesn't.
Start from there, and it would be best you share the code snippet to make it more elaborate.
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.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
I fetch below error
GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1
2020-11-19 19:32:10.000 20105-20105/com.example.popularmoviebycookies E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.popularmoviebycookies, PID: 20105
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View androidx.recyclerview.widget.RecyclerView.findViewById(int)' on a null object reference
The error says that your getting NullPointerException on the recyclerView. So it's most likely that you haven't initialized the recyclerView before performing any action on it.
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();
}