简体   繁体   English

解析请求返回空JSONArray

[英]Parse request returning a null JSONArray

I am using parse.com as the server for an android app. 我正在使用parse.com作为Android应用程序的服务器。 I am attempting to query the parse database and get a JSON array, but unfortunately the call for the array is returning null. 我正在尝试查询解析数据库并获取JSON数组,但不幸的是,对该数组的调用返回了null。 The following is the code on my app. 以下是我的应用程序上的代码。

ParseUser currentUser = ParseUser.getCurrentUser();
JSONArray myArray = (JSONArray) currentUser.getJSONArray("links");
System.out.println(currentUser.get("username"));
String sample = myArray.toString();
System.out.println(sample);

The following is a sample row from my databse on parse. 以下是我的数据库解析后的示例行。

objectId String | username String | password String | links Array

AD5HkKpJzB           foug              (hidden)       ["like","this"] 

My code above gets a reference to the current user. 我上面的代码获得了对当前用户的引用。 I am able to retrieve other data, say "username". 我能够检索其他数据,例如“用户名”。 Unfortunately, the "links" field returns null. 不幸的是,“链接”字段返回null。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

Note, the above code crashes since myArray is null. 注意,由于myArray为null,因此以上代码崩溃。

To clarify, ParseUser is a class belonging to parse.com. 为了明确起见,ParseUser是属于parse.com的类。

The following is my log report. 以下是我的日志报告。

03-01 21:48:50.687: I/Process(22225): Sending signal. PID: 22225 SIG: 9
03-01 21:49:48.729: I/System.out(22395): foug
03-01 21:49:48.729: D/AndroidRuntime(22395): Shutting down VM
03-01 21:49:48.729: W/dalvikvm(22395): threadid=1: thread exiting with uncaught exception (group=0x414a2930)
03-01 21:49:48.729: E/AndroidRuntime(22395): FATAL EXCEPTION: main
03-01 21:49:48.729: E/AndroidRuntime(22395): java.lang.RuntimeException: Unable to resume activity {com.harris.chain/com.harris.chain.MainActivity}: java.lang.NullPointerException
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2870)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2899)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.os.Looper.loop(Looper.java:137)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread.main(ActivityThread.java:5227)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at java.lang.reflect.Method.invokeNative(Native Method)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at java.lang.reflect.Method.invoke(Method.java:511)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at dalvik.system.NativeStart.main(Native Method)
03-01 21:49:48.729: E/AndroidRuntime(22395): Caused by: java.lang.NullPointerException
03-01 21:49:48.729: E/AndroidRuntime(22395):    at com.harris.chain.MainActivity.getLatestLinks(MainActivity.java:36)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at com.harris.chain.MainActivity.onResume(MainActivity.java:27)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.Activity.performResume(Activity.java:5182)
03-01 21:49:48.729: E/AndroidRuntime(22395):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2860)
03-01 21:49:48.729: E/AndroidRuntime(22395):    ... 12 more

As you can see, I am able to successfully retrieve the username "foug" from the database. 如您所见,我能够从数据库中成功检索用户名“ foug”。 But the JSONArray requests still returns null./ 但是JSONArray请求仍然返回null。

For me, hardcoding data directly into Parse's database failed to actually save the data or either didn't allow me to access it from the app. 对我来说,直接将数据硬编码到Parse的数据库中实际上无法保存数据,或者不允许我从应用程序访问它。 Once I used the app to place data into Parse's database, I was able to retrieve the data. 一旦我使用该应用程序将数据放入Parse的数据库中,便能够检索数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM