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)
我試圖搜索我的解析數據庫標題爲「主要」的所有在「Parent4」(關係)字段中具有空關係的項目,並將它們顯示到我的字符串列表(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
問:你能澄清你所說的 「query.whereDoesNotExist(」 Parent4" )的意思; 「當我想要打印查詢的計數時,似乎導致空指針異常? 「在哪一行是被調用的異常?'whereDoesNotExist'或'count()'後面的 – cjds 2014-12-07 00:08:25
不幸的是我不確定。我的eclipse日誌似乎並沒有說12-06 18:09:41.636:D/AndroidRuntime (2121):---------開始崩潰 12-06 18:09:41.659:E/AndroidRuntime(2121):致命例外:主要 12-06 18:09:41.659:E/AndroidRuntime (2121):進程:com.parse.starter,PID:2121 12-06 18:09:41.659:E/AndroidRuntime(2121):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.parse.starter/com.parse.starter.ParseStarterProjectActivity}:java.lang.NullPointerException:嘗試在空對象引用 – user4333097 2014-12-07 00:13:31
上調用虛擬方法'int org.json.JSONObject.optInt(java.lang.String)'您是否也可以發佈錯誤日誌? – cjds 2014-12-07 00:15:38