1.在外部開啟activity時需要新開一個task,從service里開啟activity時出現了這個異常。
W/System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?W/System.err: at android.app.ContextImpl.startActivity(ContextImpl.java:944)W/System.err: at android.app.ContextImpl.startActivity(ContextImpl.java:931)
表示要添加一個Flag,建議的FLAG_ACTIVITY_NEW_TASK是一種activity啟動方式,創建一個新的activity.
2.在setAdapter()之后加addHeaderView()會發生異常.
W/System.err: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.W/System.err: at android.widget.ListView.addHeaderView(ListView.java:257)W/System.err: at android.widget.ListView.addHeaderView(ListView.java:286)
3.TextView.setText()只能放charsequence類的參數,如果放的是整型數字,會報如下錯誤。
出現這個異常的原因的setText()里也可以放字符串資源id,如果放的是整形則會去R文件里找這個id對應的字符串,所以會出現NotFoundException的異常,即是找不到這個資源id所對應的文字。
注:CharSequence類的子類有String,StringBuffer,StringBuilder
E/InputEventReceiver: Exception dispatching input event.E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallbackE/MessageQueue-JNI: android.content.res.Resources$NotFoundException: String resource ID #0x28
4.spinner設置監聽問題
如果用onItemClickListener會發生異常,異常如下。
setOnItemClickListener cannot be used with a spinner.
應該用onItemSelectedListener,這是一個很容易就會踩的坑。
W/System.err: java.lang.RuntimeException: Unable to start activity java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner.W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)W/System.err: at android.app.ActivityThread.access$600(ActivityThread.java:141)W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99)W/System.err: at android.os.Looper.loop(Looper.java:137)W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5041)W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)W/System.err: at java.lang.reflect.Method.invoke(Method.java:511)W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)W/System.err: at dalvik.system.NativeStart.main(Native Method)W/System.err: Caused by: java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner.
5.在service里調用progressDialog.show()方法時,會出現異常
如果沒有將progress設為可懸浮在其它應用上方,并設置相應的權限,那么在service等其它組件中調用dialog.show()時,會無法獲得當前windows,故無法正常顯示dialog.
W/System.err: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an applicationW/System.err: at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)W/System.err: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)W/System.err: at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)W/System.err: at android.app.Dialog.show(Dialog.java:281)
//context傳入為application progressDialog = new ProgressDialog(context); progressDialog.setMessage(msg); progressDialog.setCancelable(cancelable); progressDialog.setCanceledOnTouchOutside(false); progressDialog.show();
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VEVB武林網的支持。
新聞熱點
疑難解答