我有一个已经向 GCM 注册的设备。我试过搜索,但我找不到任何类似的问题。大多数用户似乎在让 getRegistrationId 返回非空字符串时遇到问题。关于为什么这会导致错误的任何想法?
public class UploadOption extends Activity{
Intent extras = getIntent();
String optionid = extras.getStringExtra("KEY_OPTION");
String duration = extras.getStringExtra("KEY_DURATION");
String reward = extras.getStringExtra("KEY_REWARD");
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.debug_layout);
final String regId = GCMRegistrar.getRegistrationId(this);
TextView tvDebug = (TextView) findViewById(R.id.tvDebug);
tvDebug.setText(regId);
// Stores option id, php grabs option.
//new Upload().execute();
}
}
错误日志如下:
01-18 18:02:51.756: D/AndroidRuntime(4478): Shutting down VM
01-18 18:02:51.756: W/dalvikvm(4478): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
01-18 18:02:51.803: E/AndroidRuntime(4478): FATAL EXCEPTION: main
01-18 18:02:51.803: E/AndroidRuntime(4478): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.matt.drapp/com.matt.drapp.UploadOption}: java.lang.NullPointerException
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.os.Looper.loop(Looper.java:130)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-18 18:02:51.803: E/AndroidRuntime(4478): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 18:02:51.803: E/AndroidRuntime(4478): at java.lang.reflect.Method.invoke(Method.java:507)
01-18 18:02:51.803: E/AndroidRuntime(4478): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
01-18 18:02:51.803: E/AndroidRuntime(4478): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-18 18:02:51.803: E/AndroidRuntime(4478): at dalvik.system.NativeStart.main(Native Method)
01-18 18:02:51.803: E/AndroidRuntime(4478): Caused by: java.lang.NullPointerException
01-18 18:02:51.803: E/AndroidRuntime(4478): at com.matt.drapp.UploadOption.<init>(UploadOption.java:32)
01-18 18:02:51.803: E/AndroidRuntime(4478): at java.lang.Class.newInstanceImpl(Native Method)
01-18 18:02:51.803: E/AndroidRuntime(4478): at java.lang.Class.newInstance(Class.java:1409)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-18 18:02:51.803: E/AndroidRuntime(4478): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
01-18 18:02:51.803: E/AndroidRuntime(4478): ... 11 more