標籤:
以下問題都是自己在開發中親身碰到的 ,在這裡留個備份,方便下次查閱。
1、java.lang.IllegalStateException ,Cannot execute task: the task has already been executed (a task can be executed only once)
非法執行異常,大致是說這個任務已經執行過了,只能執行一個任務
解決:重新new一個任務執行即可。 之前是一開始就初始化任務類 ,在需要執行的地方再用執行個體對象execute執行
2、java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fozero.app.interfcalltest/com.fozero.app.interfcalltest.PhoneQueryActivity}: java.lang.NullPointerException
運行時異常,無法開啟一個活動Activity 存在空異常
解決:找了很久發現是跳轉的目標Activity中初始化UI組件id寫錯了
3、java.lang.IllegalStateException: ScrollView can host only one direct child
ScrollView內部只能有一個直接的子項目
解決:將所有的組件放入到Linearlayout布局中,再講learnlayout布局包含在ScrollView中
4、android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
子線程更新UI 會發生該異常,解決方案是通過藉助handle類來更新UI
5、android.content.res.Resources$NotFoundException: String resource ID #0xd7e
在比如TextView的setText()方法中向括弧中填入了一個int類型的東西啊?我剛剛也遇到了這個問題,一頓好找,終於發現了。對於數字很多時候當做資源的id而不僅僅是數字,比如這裡的setText()
TextView的.setText()方法有兩個:
1、setText(int resid) 這個方法裡面的參數是R.string.*,也就是你把字串已經定義好的;
2、setText(CharSequence text) 這個方法裡面的參數可以看做是字串類型的,這種setText(""+count)方式相當於是把count強制轉換成了字串類型的,或者也可以setText(String.valueOf(count))進行轉換,兩者都是把int型轉換成String型的。
6、Unable to resolve target ‘android-XX
出現 “Unable to resolve target ‘android-XX‘”,解決辦法進入你的android project跟目錄,找到此檔案 project.properties(或default.properties),找到target=android-XX出現此錯是因為你的android環境跟此處不對應,那麼,你只需要將此處的android版本改成你機器上配置的android版本即可,例如target=android-15
7、Unable to add window -- token null is not for an application
在activity中使用AlertDialog對話方塊時候出現的錯誤,這裡context使用了application的context
導致報這個錯是在於new AlertDialog.Builder(mcontext),雖然這裡的參數是AlertDialog.Builder(Context context)但我們不能使用getApplicationContext()獲得的Context,而必須使用Activity,因為只有一個Activity才能添加一個表單。
解決方案:將new AlertDialog.Builder(Context context)中的參數用Activity.this(Activity是你的Activity的名稱)來填充就可以正確的建立一個Dialog了。
8、android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
在調用Context.startActivity(intent)的時候報錯 ,解決方案:
在前面加上intent.addFlags(FLAG_ACTIVITY_NEW_TASK)或者使用Activity.startActivity(intent)
android開發中遇到的各種問題收集--不定期更新