MyFirebaseInstanceIDService上的java.lang.NullPointerException只有几次

时间:2018-03-05 05:03:32

标签: java android nullpointerexception

我在public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { Response response; SharedPreferences sharedPrefs; SharedPreferences.Editor ed; @Override public void onTokenRefresh() { String token = FirebaseInstanceId.getInstance().getToken(); sharedPrefs = getSharedPreferences("settings", MODE_PRIVATE); ed = sharedPrefs.edit(); ed.putString("tokana", token); ed.commit(); registerToken(token); } private void registerToken(String token) { OkHttpClient client = new OkHttpClient(); RequestBody body = new FormBody.Builder() .add("Token",token) .build(); Request request = new Request.Builder() .url("http://example.com/register.php") .post(body) .build(); try { response = client.newCall(request).execute(); // System.out.println("working..."); } catch (IOException e) { e.printStackTrace(); }finally { response.body().close(); } } } 类上遇到空指针异常问题。我用过try catch但仍存在问题。请帮我找到问题所在。提前谢谢。

java.lang.NullPointerException: 

at com.ramropatro.app.MyFirebaseInstanceIDService.onTokenRefresh (MyFirebaseInstanceIDService.java)
or                     .registerToken (MyFirebaseInstanceIDService.java)

at com.ramropatro.app.MyFirebaseInstanceIDService.onTokenRefresh (MyFirebaseInstanceIDService.java)
or                     .registerToken (MyFirebaseInstanceIDService.java)

at com.google.firebase.iid.FirebaseInstanceIdService.onTokenRefresh (FirebaseInstanceIdService.java)
or                     .zza (FirebaseInstanceIdService.java)
or                     .zzbI (FirebaseInstanceIdService.java)
or                     .zzca (FirebaseInstanceIdService.java)
or                     .zzhi (FirebaseInstanceIdService.java)
or                     .zzo (FirebaseInstanceIdService.java)

at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent (FirebaseInstanceIdService.java)
or                     .zzbK (FirebaseInstanceIdService.java)
or                     .zzbZ (FirebaseInstanceIdService.java)

at com.google.firebase.iid.zzc.run (zzc.java)

at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112)

at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587)

at java.lang.Thread.run (Thread.java:818)

某些设备上会显示此问题。以下是Play商店的崩溃报告。

<!-- language: lang-js -->
    //add dummy function to test jquery in Node
    function fn1( value ){ console.log( "fn1 says " + value );}  
function fn2( value ) {console.log( "fn2 says " + value ); return false;}
    var jsdom = require('jsdom');
    const { JSDOM } = jsdom;
    const { window } = new JSDOM();
    const { document } = (new JSDOM('')).window;
    //comment out the line below it create problem
    //global.document = document;
    var $ = jQuery = require('jquery')(window);
    var callbacks = $.Callbacks();
    callbacks.add(fn1);
    callbacks.fire("foo!");
    callbacks.add( fn2 ); 
    callbacks.fire( "fool!" );

0 个答案:

没有答案