在android中使用GCM获取JSONArray
我使用GCM从服务器获取值。当我试图得到一个字符串时,它工作正常。现在我必须使用JSON获取值数组。在这里,我的工作如下,但它的崩溃现在无法准确地找到错误 请查找为阵列实现时生成的代码和日志在android中使用GCM获取JSONArray,android,google-cloud-messaging,android-json,Android,Google Cloud Messaging,Android Json,我使用GCM从服务器获取值。当我试图得到一个字符串时,它工作正常。现在我必须使用JSON获取值数组。在这里,我的工作如下,但它的崩溃现在无法准确地找到错误 请查找为阵列实现时生成的代码和日志 // receiving push messages private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() { String latId; String lonId;
// receiving push messages
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
String latId;
String lonId;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String markerArray = intent.getExtras().getString(
"message");
JSONArray jResponse = null;
try {
JSONObject jResult = new JSONObject(markerArray);
jResponse = jResult.getJSONArray("user_position");
for(int i=0;i<jResponse.length();i++){
JSONObject posInfo = jResponse.getJSONObject(i);
latId = posInfo.getString("lat");
lonId = posInfo.getString("lon");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Waking up mobile if it is sleeping
WakeLocker.acquire(getApplicationContext());
System.out.println("new message " + latId);
System.out.println("new message " + lonId);
/**
* Take appropriate action on this message depending upon your app
* requirement For now i am just displaying it on the screen
* */
// Releasing wake lock
WakeLocker.release();
}
};
你的logcat在哪里?@MD现在检查我已经添加了日志文件try
Bundle extras=intent.getExtras()如果(extras!=null){…}
@MD Nop再次得到相同的结果error@Munchoo请在源代码中突出显示第296行。
java.lang.RuntimeException: Error receiving broadcast Intent { act=info.ae.su.DISPLAY_MESSAGE flg=0x10 (has extras) } in info.ae.su.MainActivity$1@41f0b070
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:782)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at info.ae.su.MainActivity$1.onReceive(MainActivity.java:296)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:772)