if(someObject != null) { someObject.doSomething(); //錯誤行放裡面 } else { Log.i("Tag","空值"); // do something other }try catch
try { someObject.doSomething(); //錯誤行放裡面 } catch(NullPointerException e) { Log.i("Tag","空值"); // do something other }參考來源:http://stackoverflow.com/questions/2931065/how-to-handle-nullpointerexception-in-java
沒有留言 :
張貼留言