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();
}
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.
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)
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.
I am trying to fix this error but I am kind of not seeing where it comes from.
From my fragment which creates new user I am calling another fragmentDialog (on ImageButton Click) which enables me to pick a photo from camera or gallery. Gallery works fine, but camera does not. In this line:
Uri photoUri = FileProvider.getUriForFile(globalContext, getActivity().getPackageName() + ".provider", getCameraFile());
I am getting this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
All the data is displaying correctly (I check in logs).
Where cna be the issue?
Regards,
Grzegorz
EDIT:
Full stack trace:
FATAL EXCEPTION: main
Process: com.myapp.myapp, PID: 27523
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:583)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:557)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:399)
at com.myapp.myapp.utils.PictureDialog.onTakePhoto(PictureDialog.java:80)
at com.myapp.myapp.utils.PictureDialog_ViewBinding$1.doClick(PictureDialog_ViewBinding.java:32)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:5184)
at android.view.View$PerformClick.run(View.java:20893)
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:5940)
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:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
FileProvider cannot find the <provider> element in the manifest that has an android:authorities value equal to getActivity().getPackageName() + ".provider". Specifically, this code results in a null value for info:
final ProviderInfo info = context.getPackageManager()
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
(where context is the first parameter to getUriForFile() and authority is the second parameter to getUriForFile())
Make sure that your supplied authority string matches your <provider> element.
I have encountered a problem in which when ever I use
final MediaPlayer tick = MediaPlayer.create(getApplicationContext(), R.raw.tick);
tick.start();// tick is a short .mp3 file
in my app, no matter where, I get:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
at com.a.aar.MainActivity.onClicks(MainActivity.java:123)
at com.a.aar.MainActivity$2.onClick(MainActivity.java:97)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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)
But, whenever I use a slightly shorter sound effect, the app runs great.(I need a short sound because I want a lot of sounds coming fast and so the sounds will not stop)
What is the reason to this error and how can I solve it?