last day (21 days later) » 

6:00 PM
Hi :)
So
Thanks for your will to help me ;)
 
 
1 hour later…
7:18 PM
If you have any questions go ahead...
 
7:37 PM
Hi
So
I tried adding the intent
in that if block
yeah
and it ends up with two NPEs I commented lastly
 
Share the stack trace for Exceptions and relative code.
 
Ok, trying now...
 
7:51 PM
sO
With this code (same as original code snipp): ``` 3rdClass MFP = new 3rdClass();
MFP.3rdMethod(TAG.toString());``` I got this tracke: ```09-13 22:50:57.796 2900 2900 E <Tag>: <...> Data: <...> Message: null```
 
I can't make any sense of this.
Why don't you just send the logs, and I mean the complete logs detailing the stacktrace thrown into logcat.
 
that is the point
that is all logcat is showing
I am directly getting logs via C:\Users\<user>\AppData\Local\Android\Sdk\platform-tools>adb logcat *:F *:E
Ok
here you go
which means that activity and/or context is null
in Fitness.getSessionsClient((Activity) this, Objects.requireNonNull(GoogleSignIn.getLastSignedInAccount(SyncActivity.mContext)))
but if I try your suggested intent object constructor
I got different error - "Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference"
which then suggests that activity is filled but context is not having properly inhertitted package definition ...
Hope this gives a bit more sense..
If I change "Intent intent = new Intent(SyncActivity.getInstance(), MFPalInterface.class);" to "Intent intent = new Intent(MainActivity.getInstance(), MFPalInterface.class);", I get "Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference"
MainActivity = 1stClass ; SyncActivity = 2ndClass ; MFPalInterface = 3rdClass.
W/System.err: java.lang.NullPointerException
W/System.err: at java.util.Objects.requireNonNull(Objects.java:203)
at com.linardsl.libhacontimig.MFPalInterface.trackMFP(MFPalInterface.java:79)
W/System.err: at com.linardsl.libhacontimig.SyncActivity.setJSON(SyncActivity.java:197)
at com.linardsl.libhacontimig.MainActivity.CheckPerm(MainActivity.java:250)
at com.linardsl.libhacontimig.MainActivity$2$1.onClick(MainActivity.java:110)
at com.google.android.material.snackbar.Snackbar$1.onClick(Snackbar.java:317)
2nd stack trace:
W/System.err: java.lang.NullPointerException
W/System.err: at java.util.Objects.requireNonNull(Objects.java:203)
at com.linardsl.libhacontimig.MFPalInterface.trackMFP(MFPalInterface.java:79)
W/System.err: at com.linardsl.libhacontimig.SyncActivity.setJSON(SyncActivity.java:196)
W/System.err: at com.linardsl.libhacontimig.MainActivity.CheckPerm(MainActivity.java:250)
W/System.err: at com.linardsl.libhacontimig.MainActivity$2$1.onClick(MainActivity.java:110)
at com.google.android.material.snackbar.Snackbar$1.onClick(Snackbar.java:317)
With same code piece as shared in initial code snipps in the question:
                MFPalInterface MFP = new MFPalInterface();
                MFP.trackMFP(TAG.toString());
3rd stack trace:
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
W/System.err: at android.content.ComponentName.<init>(ComponentName.java:130)
W/System.err: at android.content.Intent.<init>(Intent.java:6082)
W/System.err: at com.linardsl.libhacontimig.SyncActivity.setJSON(SyncActivity.java:197)
W/System.err: at com.linardsl.libhacontimig.MainActivity.CheckPerm(MainActivity.java:250)
With following code piece:
                MFPalInterface MFP = new MFPalInterface();
                Intent intent = new Intent(MFPalInterface.getInstance(), MFPalInterface.class);
                MFP.startActivity(intent);
@Abbas^ ;)
 
9:19 PM
4rd stack trace:
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
W/System.err: at android.content.ContextWrapper.getPackageName(ContextWrapper.java:142)
W/System.err: at android.content.ComponentName.<init>(ComponentName.java:130)
W/System.err: at android.content.Intent.<init>(Intent.java:6082)
W/System.err: at com.linardsl.libhacontimig.SyncActivity.setJSON(SyncActivity.java:197)
With following code piece:
                MFPalInterface MFP = new MFPalInterface();
                Intent intent = new Intent(this, MFPalInterface.class);
                MFP.startActivity(intent);
 
9:50 PM
First off make sure that your SyncActivity is being created the same way (with intent). Once you're sure it is, make sure the instance field you return in the getInstance method is not null.
Note that while instance will not be null in case you created the SyncActivity yourself, it will not provide any context for the use of package manager.
Intent depends on the Context of the application, activity or a service depending on the how it is used to obtain Package Information. This Pacakge Information will only be provided to an Activity if it has been created by the Android Framework itself.
And so, it is necessary that all the instance of all the Activities are created through intent in your java code, except your launcher activity which gets its launcher intent through the android system when the user clicks on your application's icon.
Finally there is no need to give a shout through the comments in the post. I will respond on this thread whenever I can.
 

  last day (21 days later) »