我正在尝试查询在我的应用中注册的所有parse.com用户。我按照指南编写了这个查询
try{
name=Name.getText().toString();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereMatches("username", name);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
if (!objects.isEmpty()) {
show.setText(String.valueOf(objects.size()));
for (ParseUser singleobject : objects) {
mail[i] = singleobject.get("email").toString();
uname[i] = singleobject.get("username").toString();
i++;
}
} else {
show.setText("No Tuples");
}
} else {
Toast.makeText(getApplicationContext(), "Query Not Successful", Toast.LENGTH_LONG).show();
}
}
});
}catch (NullPointerException x){
Toast.makeText(getApplicationContext(), "Null Pointer Exception", Toast.LENGTH_LONG);
}}
当输入检索单个元组时,此查询很有效但当我提供检索多个元组的输入时,它会抛出一个像这样的NULL POINTER EXCEPTION
Process: com.example.nirmal.sportsparse, PID: 15097
java.lang.NullPointerException
at com.example.nirmal.sportsparse.search_players$2.done(search_players.java:108)
at com.example.nirmal.sportsparse.search_players$2.done(search_players.java:99)
at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
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:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
错误代码表示findInBackground()
和for
中有一个NULL指针
在libcore.io.ErrnoException: close failed: EBADF (Bad file number)
at libcore.io.Posix.close(Native Method)
at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
at com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:220)
at com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
at com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
at com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:700)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
循环内。我确信我提供的输入必须检索至少2个元组。
有时它也会抛出此错误,我不知道这意味着什么
String name,mail[]=new String[100],uname[]=new String[100];
数组声明如下
Thread.setDefaultUncaughtExceptionHandler((Thread t, Throwable e) -> {
System.out.println(t + " throws exception: " + e);
});
谁能告诉我哪里出错?
答案 0 :(得分:1)
在回调&#34;完成&#34; ,JSON API,通常允许2个步骤...
检查元素是否存在
Stringify元素
请注意
uname[i] = singleobject.get("username").toString();
尝试一次完成所有操作并在可能是&#34;未定义的列上抛出异常&#34;在返回的parse对象中。
先检查
然后stringify