2013-05-26 2 views
3

Я использую код sameple с сайта разработчика, но получаю ошибку при компиляции. http://developer.android.com/google/gcm/gs.htmlОшибка при использовании Asynctask для регистрации GCM

скопировав код ниже

private void registerBackground() { 
new AsyncTask() { 
    @Override 
    protected String doInBackground(Void... params) { 
     String msg = ""; 
     try { 
      regid = gcm.register(GCM_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. 

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

      // Save the regid for future use - no need to register again. 
      SharedPreferences.Editor editor = prefs.edit(); 
      editor.putString(PROPERTY_REG_ID, regid); 
      editor.commit(); 
     } catch (IOException ex) { 
      msg = "Error :" + ex.getMessage(); 
     } 
     return msg; 
    } 
    // Once registration is done, display the registration status 
    // string in the Activity's UI. 
    @Override 
    protected void onPostExecute(String msg) { 
     mDisplay.append(msg + "\n"); 
    } 
}.execute(null, null, null); 
} 

Я получаю ошибку при составлении заявив, что «AsyncTask является исходным типом. Ссылка на общий тип должен быть paramterised.

ответ

9

Вы не объявлены общие параметры типа .

изменение

new AsyncTask() { 

к

new AsyncTask<Void,Void,String>() { 

, а также,

execute(null, null, null); 

может быть изменен на

execute(); 
+0

спасибо за отметив, что. Теперь он работает отлично. – user1938357

Смежные вопросы