执行Asynctask时的java.lang.NullPointerException

时间:2014-04-12 19:12:25

标签: android android-asynctask google-cloud-messaging

我想将用户注册到gcm服务器,所以我使用了这个函数:

private void registerInBackground() {
         new AsyncTask<Void,Void,String>() {
                @Override
                protected String doInBackground(Void... params) {
                    String msg = "";
                    try {
                        if (gcm == null) {
                            gcm = GoogleCloudMessaging.getInstance(context);
                        }
                        regid = gcm.register(SENDER_ID);
                        msg = "Device registered, registration ID=" + regid;

                        // You should send the registration ID to your server over HTTP,
                        // so it can use GCM/HTTP or CCS to send messages to your app.
                        // The request to your server should be authenticated if your app
                        // is using accounts.
                        sendRegistrationIdToBackend();

                        // For this demo: we don't need to send it because the device
                        // will send upstream messages to a server that echo back the
                        // message using the 'from' address in the message.

                        // Persist the regID - no need to register again.
                      // storeRegistrationId(context, regid);
                    } catch (IOException ex) {
                        msg = "Error :" + ex.getMessage();
                        // If there is an error, don't just keep trying to register.
                        // Require the user to click a button again, or perform
                        // exponential back-off.
                    }
                    return msg;
                }

                @Override
                protected void onPostExecute(String msg) {
                    mDisplay.append(msg + "\n");
                }
            }.execute(null, null, null);

        }

它与描述here的功能相同,所以我很惊讶得到一个NullPOinterEXCEPTION错误,我认为这是因为这行:execute(null,null,null,null),但这是google给出的我!我该怎么办?

0 个答案:

没有答案