欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

安卓中出現(xiàn)過的一些容易被忽略的異常整理

 更新時間:2018年12月24日 09:50:27   作者:pigdreams  
今天小編就為大家分享一篇關于安卓中出現(xiàn)過的一些容易被忽略的異常整理,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

1.在外部開啟activity時需要新開一個task,從service里開啟activity時出現(xiàn)了這個異常。

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啟動方式,創(chuàng)建一個新的activity.

2.在setAdapter()之后加addHeaderView()會發(fā)生異常.

  • When first introduced, this method could only be called before setting the adapter with setAdapter(ListAdapter). Starting with KITKAT, this method may be called at any time.
  • KITKAT:October 2013: Android 4.4, KitKat, another tasty treat. android 4.4之后可以在任何地方調用,4.4之前的版本都會報錯。
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類的參數(shù),如果放的是整型數(shù)字,會報如下錯誤。

出現(xiàn)這個異常的原因的setText()里也可以放字符串資源id,如果放的是整形則會去R文件里找這個id對應的字符串,所以會出現(xiàn)NotFoundException的異常,即是找不到這個資源id所對應的文字。

注:CharSequence類的子類有String,StringBuffer,StringBuilder

E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: android.content.res.Resources$NotFoundException: String resource ID #0x28

4.spinner設置監(jiān)聽問題

如果用onItemClickListener會發(fā)生異常,異常如下。

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()方法時,會出現(xiàn)異常

如果沒有將progress設為可懸浮在其它應用上方,并設置相應的權限,那么在service等其它組件中調用dialog.show()時,會無法獲得當前windows,故無法正常顯示dialog.

W/System.err: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
W/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();

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接

相關文章

最新評論