1. 程式人生 > >Android程式設計心得-常見問題解決辦法(不斷更新中..)

Android程式設計心得-常見問題解決辦法(不斷更新中..)

1.進行模擬器除錯時出現 Failed to install Remote_Monitoring.apk on device 'emulator-5554': timeout

     解決辦法:在Eclipse-->Window-->Preferences-->Android-->DDMS-->ADB connection time out (ms) 中將預設的5000ms改為10000ms或更長

2.當前工程出現紅色感嘆號

    解決辦法:可能是引用jar包的地址不正確,4.0以下引用的是lib資料夾內的地址,4.0就變成libs了

3.Failed to install Remote_Monitoring.apk on device 'emulator-5554': EOF

    解決辦法:關閉模擬器,重啟模擬器

4.android.os.NetworkOnMainThreadException

    解決辦法:當一個應用程式試圖在它的主執行緒執行網路操作的時候就會丟擲這個異常,將網路請求寫線上程中或寫到AsyncTask中

5.The content of the adapter has changed but ListView did not receive a notification make sure the content of your adapter is not modified from a background thread . but only from the UI thread

   解決辦法:

 1.改變介面卡Adapter內容時不要在後臺執行緒中,必須在UI執行緒中處理,這點可以通過Handler傳出來解決。

  2.親身經歷,當你改變了介面卡繫結的泛型List<T>的值時,比如泛型物件是list,你呼叫了list.clear(),一定要在主執行緒通知,也就是呼叫Adapter的notifyDataSetChanged()


6.Error receiving broadcast Intent { act=android.bluetooth.adapter.action.DISC

解決辦法:在廣播接收器的OnReceive函式中,將除了String action = intent.getAction() 的操作放到if語句中,保證廣播接收器的不同ACTION不會處理相同的取函式程式碼

7.java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bluecomrfmeter/com.bluecomrfmeter.BlueComConnectActivity}: java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10184 nor current process has android.permission.BLUETOOTH.

解決辦法:在AndroidManifest.xml 中加上    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 許可權