Recently, Android devices sometimes throws that error message and crashes:
java.lang.NullPointerException:
at com.happycenter.happycan.android.MyFirebaseInstanceIDService.a (Unknown Source:39)
at com.google.firebase.iid.FirebaseInstanceIdService.b (Unknown Source:12)
at com.google.firebase.iid.i.run (Unknown Source:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
at java.lang.Thread.run (Thread.java:764)[/code]
It is obviously related to Firebase.
I sometimes see this report in PlayStore panel.
My Dependencies:
com.android.tools.build:gradle:3.4.2
com.google.gms:google-services:3.2.0
com.google.firebase:firebase-messaging:11.8.0
buildToolsVersion 28.0.3
compileSdkVersion 28
minSdkVersion 14
targetSdkVersion 28
Source Code:
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
String token = FirebaseInstanceId.getInstance().getToken();
registerToken(token);
}
private void registerToken(String token){
FileHandle file;
file = Gdx.files.local("data/t.txt");
file.writeString(token, false);
}
}
What is the reason behind this problem and how can I solve it?