gpt4 book ai didi

Android GCM RegistrationID 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:09 25 4
gpt4 key购买 nike

我有一个已经在 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

最佳答案

问题是由于 Intent 代码造成的。请记住, Activity 仅在 onCreate() 之后初始化,并且您正试图在 Activity 初始​​化之前获取 Intent 值。

将下面的代码放在onCreate();

Intent extras = getIntent();
String optionid = extras.getStringExtra("KEY_OPTION");
String duration = extras.getStringExtra("KEY_DURATION");
String reward = extras.getStringExtra("KEY_REWARD");

它应该可以工作。

关于Android GCM RegistrationID 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14410434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com