Running Volley request in background service - android

I want to use Volley to pull some JSON data from a Service class, but I keep receiving File Cache crashes at RequestQueue mRequestQueue = Volley.newRequestQueue(this); in the service class.
It works fine in my main application.
Edit
FATAL EXCEPTION: main
Process: com.xxx.yyy, PID: 28290
java.lang.RuntimeException: Unable to instantiate service
com.idlctech.etherpooler.PoolerService:
java.lang.NullPointerException: Attempt to invoke virtual method
'android.content.Context
android.content.Context.getApplicationContext()' on a null object
reference
at
android.app.ActivityThread.handleCreateService(ActivityThread.java:3121)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1530)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5969)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'android.content.Context
android.content.Context.getApplicationContext()' on a null object
reference
at
android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:106)
at
xxx.yyy.zzz.PoolerService.(PoolerService.java:38)
at java.lang.Class.newInstance(Native Method)
at
android.app.ActivityThread.handleCreateService(ActivityThread.java:3118)
at android.app.ActivityThread.-wrap5(ActivityThread.java) 
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1530) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:5969)

Define the service in the manifest.
<application ... >
<service android:name=".ExampleService" />
...
</application>
Look at this post. With the code you have provided us that's all I can think of.

I wasn't passing the correct context.

Related

Accessing named sharedpreference from a service

I'm trying to access SharedPreference from a service and getting an error which I cannot find anywhere on the net. Any help is appreciated. Thank you.
code
sharedPref = getApplicationContext().getSharedPreferences("FlutterSharedPreferences",Context.MODE_PRIVATE|Context.MODE_MULTI_PROCESS);
2020-09-10 21:16:04.057 10186-10186/com.example.demo1 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.demo1, PID: 10186
java.lang.RuntimeException: Unable to start service com.example.demo1.MorningReset#ce7eae1 with Intent { flg=0x4 cmp=com.example.demo1/.MorningReset (has extras) }: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3686)
at android.app.ActivityThread.access$1600(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.UserManager.isUserUnlockingOrUnlocked(int)' on a null object reference
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:418)
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:404)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:174)
at com.example.demo1.MorningReset.onStartCommand(MorningReset.java:25)
This error appears only when accessing the SharedPreference from a service. The same line of code works fine in an activity.

AN ANDROID APP KEEPS CRASHING WHEN I OPEN IT GIVES THE MESSAGE "HAS STOPPED WORKING"

I tried to run my APP, I just ended up getting a message "MegaVidi Stopped Working", I tried to run some tests and got the following errors
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.megatechnologyteam.megavidi/com.megatechnologyteam.megavidi.SplashActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.hide()' on a null object reference
FATAL EXCEPTION: main
Process: com.megatechnologyteam.megavidi, PID: 10886
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.megatechnologyteam.megavidi/com.megatechnologyteam.megavidi.SplashActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.hide()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.hide()' on a null object reference
at com.megatechnologyteam.megavidi.SplashActivity.onCreate(SplashActivity.java:20)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
How do I solve this so that my APP can run properly?
Help me please
Please locate the object in your code
com.megatechnologyteam.megavidi.SplashActivity.onCreate(SplashActivity.java:20)
There should have an object of the class ActionBar attempting calling hide().
This just object is actually null. Please check.
In SplashActivity you are trying to hide the ActionBar which is null (that is why you are getting NullPointerException).
To resolve the issue, remove the line where you are calling ActionBar.hide().
I cannot tell you more than this without seeing the code of SplashActivity.

Null Pointer Exception While Creating side bar navigation in android

I am trying to Create side bar navigation in android but there is one problem I am facing.I went through so many post on stackoverflow but it didn't solved my problem
I am following the tutorial exactly mentioned here
But when I a running my app I am getting error
Process: com.example.deepak.myapplication, PID: 26704
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.deepak.myapplication/com.example.deepak.myapplication.Naviagtion}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2721)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2782)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1521)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6228)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at com.example.deepak.myapplication.Naviagtion.onCreate(Naviagtion.java:29)
at android.app.Activity.performCreate(Activity.java:6871)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2674)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2782) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1521) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:163) 
at android.app.ActivityThread.main(ActivityThread.java:6228) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) 
I am using styles as mentioned
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Also I am Extending AppCompatActivity
So please help me and let me know where I am going wrong
you have not set ActionBar, put this line above
setSupportActionBar(toolbar); // <--- put this
ActionBar.setDisplayHomeAsUpEnabled(true)

Google Play Store suddently began crashing every time I open it

Suddently, during regular usage of my Nexus 5, the Google Play Store started crashing every time I try to open it.
So, I tried to get the log of the error, here it is:
11664-11664/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.android.vending, PID: 11664
java.lang.RuntimeException: Unable to create application com.google.android.finsky.FinskyApp: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.AppOpsManager.checkPackage(int, java.lang.String)' on a null object reference
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:334)
at android.app.ActivityThread.handleBindApplication(<Xposed>)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
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)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.AppOpsManager.checkPackage(int, java.lang.String)' on a null object reference
at android.os.Parcel.readException(Parcel.java:1605)
at android.os.Parcel.readException(Parcel.java:1552)
at android.content.pm.IPackageInstaller$Stub$Proxy.getMySessions(IPackageInstaller.java:385)
at android.content.pm.PackageInstaller.getMySessions(PackageInstaller.java:415)
at com.google.android.finsky.installer.PackageInstallerImpl.<init>(PackageInstallerImpl.java:71)
at com.google.android.finsky.installer.PackageInstallerFactory.init(PackageInstallerFactory.java:23)
at com.google.android.finsky.FinskyApp.onCreate(FinskyApp.java:387)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) 
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:334) 
at android.app.ActivityThread.handleBindApplication(<Xposed>) 
at android.app.ActivityThread.-wrap1(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) 
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) 
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102) `
I tried to look for this error online, but couldn't find anything. I assume it's related to some system app that has one of her permissions unapproved (I don't know which could be the one), or maybe related to my Xposed Framework installation.
What could it be?
Thank you for your help.
its not any other problem did you see Attempt to invoke virtual method 'void android.app.AppOpsManager.checkPackage(int, java.lang.String)' on a null object reference. you have calling some null object reference.

Unable to start service com.google.android.gms.analytics.AnalyticsService#3399b37 with null

I am receiving these crash reports from my crash reporting tools.
I don't which code to provide here so just let me know if you want to see any particular code.
I haven't put anything related to GoogleAnalytics in onStart method as it is not mentioned in documentation.
Fatal Exception: java.lang.RuntimeException Unable to start service
com.google.android.gms.analytics.AnalyticsService#3399b37 with null:
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String android.content.Intent.getAction()' on a null object
reference
java.lang.RuntimeException: Unable to start service
com.google.android.gms.analytics.AnalyticsService#3399b37 with null:
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String android.content.Intent.getAction()' on a null object
reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2910)
at android.app.ActivityThread.access$2200(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'java.lang.String android.content.Intent.getAction()' on a null
object reference
at com.google.android.gms.analytics.AnalyticsService.onStartCommand()
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2893)
at android.app.ActivityThread.access$2200(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
This is a reported bug with the Google Analytics: https://code.google.com/p/analytics-issues/issues/detail?id=667.

Categories

Resources