在 #doInBackground() 抓檔時,會想要即時用 Toast 顯示訊息。 但是會造成錯誤:
java.lang.RuntimeException: An error occured while executing doInBackground() ...
可行的方法是在 #postExecute() 才處理。
private Exception exception; @Override protected Result doInBackground(Params... requests) { try { } catch (Exception e) { // Toast.makeText(context, "error occurs", Toast.LENGTH_LONG).show(); exception = e; } } @Override protected void onPostExecute(ListgoogleImages) { if (exception != null) { Toast.makeText(context, "error occurs", Toast.LENGTH_LONG).show(); } }
參考資料:StackOverflow: java.lang.RuntimeException: An error occured while executing doInBackground()
Android Studio 1.3 compileSdkVersion 22 buildToolsVersion "23.0.0 rc3"
沒有留言:
張貼留言