ParseObject current;
...
ParseQuery<ParseObject> query = ParseQuery.getQuery("Primary");
try{
if(current == null){
System.out.println("current is NULL"); //prints properly
System.out.println("Initial query: " + query.count()); //prints 'Initial Query: 90'
query.whereDoesNotExist("Parent4");
System.out.println("Test1"); //prints properly
System.out.println("Query Count: " + query.count()); //seems to cause nullpointer
List<ParseObject> list = query.find();
System.out.println("Test2");
for(ParseObject p: list){
listItems.add((String)p.get("Title")); //listItems used to populate listview when listview is generated
...(closing brackets,else statement, exception catching, rest of program)
我正在尝试搜索名为“Primary”的解析数据库,查找字段“Parent4”(Relation)中具有空关系的所有项目,并将它们显示到我添加到的字符串列表(listItems)中listView创建时。我知道我的数据库中的两个对象没有任何关系,所以我希望显示这两个对象的标题。我之前有一个有点工作的版本工作正常,除了我检查列表中每个对象的标题而不是对象本身,这导致我的程序中的两个对象具有相同标题后出现问题,这是一些东西这在我的计划中应该是可以接受的。
知道为什么行“query.whereDoesNotExist(”Parent4“);”当我想要打印查询的计数时,似乎导致空指针异常?或者我知道如何处理这个问题呢?
这是日志:
12-06 18:20:50.030: I/Process(2469): Sending signal. PID: 2469 SIG: 9
12-06 18:20:57.740: I/System.out(2517): current is NULL
12-06 18:20:58.159: I/System.out(2517): Initial query: 92
12-06 18:20:58.159: I/System.out(2517): Test1
12-06 18:20:58.378: D/AndroidRuntime(2517): Shutting down VM
12-06 18:20:58.379: E/AndroidRuntime(2517): FATAL EXCEPTION: main
12-06 18:20:58.379: E/AndroidRuntime(2517): Process: com.parse.starter, PID: 2517
12-06 18:20:58.379: E/AndroidRuntime(2517): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parse.starter/com.parse.starter.ParseStarterProjectActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.os.Looper.loop(Looper.java:135)
12-06 18:20:58.379: E/AndroidRuntime(2517): at android.app.ActivityThread.main(ActivityThread.java:5221)
12-06 18:20:58.379: E/AndroidRuntime(2517): at java.lang.reflect.Method.invoke(Native Method)
12-06 18:20:58.379: E/AndroidRuntime(2517): at java.lang.reflect.Method.invoke(Method.java:372)
12-06 18:20:58.379: E/AndroidRuntime(2517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-06 18:20:58.379: E/AndroidRuntime(2517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-06 18:20:58.379: E/AndroidRuntime(2517): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
12-06 18:20:58.379: E/AndroidRuntime(2517): at com.parse.ParseQuery$18.then(ParseQuery.java:1014)
12-06 18:20:58.379: E/AndroidRuntime(2517): at com.parse.ParseQuery$18.then(ParseQuery.java:1011)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.completeImmediately(Task.java:440)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$100(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$5.then(Task.java:307)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$5.then(Task.java:304)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.trySetError(Task.java:577)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.setError(Task.java:604)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10$1.then(Task.java:487)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10$1.then(Task.java:481)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.completeImmediately(Task.java:440)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.continueWith(Task.java:314)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.continueWith(Task.java:325)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10.run(Task.java:481)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.completeAfterTask(Task.java:473)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$200(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$6.then(Task.java:342)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$6.then(Task.java:339)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.trySetError(Task.java:577)
12-06 18:20:58.379: E/AndroidRuntime(2517): at com.parse.ParseRequest$4.then(ParseRequest.java:350)
12-06 18:20:58.379: E/AndroidRuntime(2517): at com.parse.ParseRequest$4.then(ParseRequest.java:344)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10.run(Task.java:477)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.completeAfterTask(Task.java:473)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$200(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$6.then(Task.java:342)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$6.then(Task.java:339)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.trySetError(Task.java:577)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.setError(Task.java:604)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10$1.then(Task.java:487)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10$1.then(Task.java:481)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.completeImmediately(Task.java:440)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.continueWith(Task.java:314)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.continueWith(Task.java:325)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10.run(Task.java:481)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.completeAfterTask(Task.java:473)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$200(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$6.then(Task.java:342)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$6.then(Task.java:339)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.trySetResult(Task.java:561)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$TaskCompletionSource.setResult(Task.java:595)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10$1.then(Task.java:489)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$10$1.then(Task.java:481)
12-06 18:20:58.379: E/AndroidRuntime(2517): at bolts.Task$9.ru
12-06 18:20:58.379: D/Error(2517): ERR: exClass=java.lang.NullPointerException
12-06 18:20:58.379: D/Error(2517): ERR: exMsg=Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
12-06 18:20:58.379: D/Error(2517): ERR: file=ParseQuery.java
12-06 18:20:58.379: D/Error(2517): ERR: class=com.parse.ParseQuery$18
12-06 18:20:58.379: D/Error(2517): ERR: method=then line=1014
12-06 18:20:58.379: D/Error(2517): ERR: stack=java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parse.starter/com.parse.starter.ParseStarterProjectActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
12-06 18:20:58.379: D/Error(2517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
12-06 18:20:58.379: D/Error(2517): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-06 18:20:58.379: D/Error(2517): at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-06 18:20:58.379: D/Error(2517): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-06 18:20:58.379: D/Error(2517): at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 18:20:58.379: D/Error(2517): at android.os.Looper.loop(Looper.java:135)
12-06 18:20:58.379: D/Error(2517): at android.app.ActivityThread.main(ActivityThread.java:5221)
12-06 18:20:58.379: D/Error(2517): at java.lang.reflect.Method.invoke(Native Method)
12-06 18:20:58.379: D/Error(2517): at java.lang.reflect.Method.invoke(Method.java:372)
12-06 18:20:58.379: D/Error(2517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-06 18:20:58.379: D/Error(2517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-06 18:20:58.379: D/Error(2517): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
12-06 18:20:58.379: D/Error(2517): at com.parse.ParseQuery$18.then(ParseQuery.java:1014)
12-06 18:20:58.379: D/Error(2517): at com.parse.ParseQuery$18.then(ParseQuery.java:1011)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.completeImmediately(Task.java:440)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$100(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$5.then(Task.java:307)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$5.then(Task.java:304)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.trySetError(Task.java:577)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.setError(Task.java:604)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10$1.then(Task.java:487)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10$1.then(Task.java:481)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.completeImmediately(Task.java:440)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.continueWith(Task.java:314)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.continueWith(Task.java:325)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10.run(Task.java:481)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.completeAfterTask(Task.java:473)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$200(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$6.then(Task.java:342)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$6.then(Task.java:339)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.trySetError(Task.java:577)
12-06 18:20:58.379: D/Error(2517): at com.parse.ParseRequest$4.then(ParseRequest.java:350)
12-06 18:20:58.379: D/Error(2517): at com.parse.ParseRequest$4.then(ParseRequest.java:344)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10.run(Task.java:477)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.completeAfterTask(Task.java:473)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$200(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$6.then(Task.java:342)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$6.then(Task.java:339)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.trySetError(Task.java:577)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.setError(Task.java:604)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10$1.then(Task.java:487)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10$1.then(Task.java:481)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.completeImmediately(Task.java:440)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.continueWith(Task.java:314)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.continueWith(Task.java:325)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10.run(Task.java:481)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.completeAfterTask(Task.java:473)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$200(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$6.then(Task.java:342)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$6.then(Task.java:339)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.runContinuations(Task.java:506)
12-06 18:20:58.379: D/Error(2517): at bolts.Task.access$600(Task.java:27)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.trySetResult(Task.java:561)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$TaskCompletionSource.setResult(Task.java:595)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10$1.then(Task.java:489)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$10$1.then(Task.java:481)
12-06 18:20:58.379: D/Error(2517): at bolts.Task$9.run(Task.java:444)
12-06 18:20:58.379: D/Error(2517): at bolts.BoltsExecutors$ImmediateExecuto
12-06 18:20:58.379: D/Error(2517): ERR: TOTAL BYTES WRITTEN: 13252
答案 0 :(得分:1)
更新: 你可以通过下一个方法来做到这一点
ParseQuery<RelationParse> innerQuery = ParseQuery.getQuery("Primary");
ParseQuery<TestParse> query = ParseQuery.getQuery("Primary");
query.whereDoesNotMatchQuery("Parent4", innerQuery);
List<TestParse> listWithEmptyRelations = query.find();