1. 程式人生 > >六、 Android常見錯誤 (持續更新中……)

六、 Android常見錯誤 (持續更新中……)

1Unable to resolve target 'android-2'

安裝低版本的api,再default.properties這個檔案中把target=android-2改成 target=android-7終於就沒有問題了。

2Invalid start tag LinearLayout

main.xml放錯檔案夾了,應該在\res\layout下。

3INSTALL_FAILED_INSUFFICIENT_STORAGE

原因:SD卡記憶體容量不夠

法一:在下圖的“Additional Emulator Command Line Options”中加上“-partition-size 128

法二:啟動模擬器,然後進入選單

settings->applications->mange applications-> select the application->select "unistall".

這樣就能徹底刪除了,然後再重新安裝這個apk就沒問題了

4No Space left on device

清除C:\Users\Lanyan\AppData\Local\Temp\AndroidEmulator資料夾下的tmp檔案

5Could not open the editor: Resource is out of sync with the file system

當右擊default.properties開啟時,出現下圖錯誤:

解決方法:右擊工程,Refresh一下就好了。

原因:Usually happens when some files are edited outside of eclipse

6Invalid project description

網上的解決方法是:在專案根目錄下的.project檔案中,找到<name>cms6.0</name>cms6.0改為和專案目錄名稱一致。

解決方法:我已經將該工程匯入Eclipse,一個工程不能重複匯入兩次;或者把你的資料夾考的別的目錄下然後重新匯入即可。

原因:有兩份相同的

AndroidManifest.xml的描述性檔案。

7java.lang.SecurityException: Requires VIBRATE permission

解決方法:在AndroidManifest.xml中加上一句

<uses-permission android:name="android.permission.VIBRATE"></uses-permission>

原因:許可權問題導致,因為使用了震動功能。

8Activity not started, its current task has been brought to the front

解決方法:在Eclipse中,“project-->clean…

原因:模擬器中還有東西在執行,也就是你要執行的activity已經有一個在模擬器中運行了不要以為你的模擬器退出到桌面了就沒有東西在跑了。在你除錯的時候異常關閉的程式有可能就有activity在執行。

9ArrayAdapter requires the resource ID to be a TextView

問題描述:java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

adapt = new ArrayAdapter <String>(this, R.layout.main, infoList);

這句中佈局main中的佈局可能不是TextView物件。

adapt = new ArrayAdapter <String>(A1, A2, A3);

引數A2是一個“resource ID to be a TextView 

解決方法:A2改為:android.R.layout.simple_spinner_dropdown_item

10R.java檔案突然不見了

解決方法:右鍵專案-->Build Project

原因:res/drawable下的檔名只能是在a~z0~9之間字元組成。

10ScrollView can host only one direct child

解決方法:需要把所有的子元素放到一個LinearLayout內部或RelativeLayout等其他佈局方式。

原因:主要是ScrollView內部只能有一個子元素,即不能並列兩個子元素。

11emulator: ERROR: the user data image is used by another emulator. aborting

沒有正常關閉導致的,刪除android-sdk-windows\.android\avd\對於版本\下的以.lock結尾的資料夾就行。

原因:.lock是加鎖,如果程式崩潰等原因導致無法清除這些以.lock結尾的資料夾,就會出現這個問題,也就是這個avd的鎖沒有被釋放,導致avd manager以為這個avd正在使用當中。

12* daemon not running. starting it now *

ADB server didn't ACK

* failed to start daemon *

已經確認adb.exe的路徑沒有問題,重啟了兩次模擬器和eclipse還是不行,上網查了下資料~

解決辦法:

1)檢視工作管理員,關閉所有adb.exe;(2)重啟eclipse即可

13android.content.res.resources notfoundexception

Manifest.xml中加上:<uses-sdk android:minSdkVersion="5"/>,或者將5改成6,其他值也一樣加1

14Unable to instantiate activity ComponentInfo

解決方案:更改activity android:name="Acitivity"activity android:name=".Acitivity"

原因:AndroidManifest.xml配置activity的路徑時出錯了

15、工程名上有紅色感嘆號

解決方案:右鍵專案名稱BuildPath--->ConfigureBuildPaht...中,然後上面有幾個選項卡找到Libraries中出現紅色叉號的包為路徑錯誤的包。到classpath中修改相應包的當前路徑。然後回到eclipseF5重新整理工程。

問題原因:工程中classpath中指向的包路徑錯誤。

解釋:用myeclipse新建web工程,在工程目錄下會生成一個.classpath配置檔案,裡面是你工程裡面引用的jar的配置。這個.classpath對你的web工程沒有什麼影響,其實是給myeclipse識別的。你說的這種情況是因為.classpath檔案裡面配置引用了某個jar,但是實際上你的lib裡面並沒有這個jar所以才會有紅色的提示。你不用拿.classpath檔案和你的jar一個個去找,你現在開啟MyEclipse右鍵單擊你的web工程,找到BuildPath-->ConfigureBuildPaht...-->然後上面有幾個選項卡找到Libraries。這裡看到的就是你工程裡面引用的所有的jar,看看是不是在某個jar圖示上有個很小的黃色的感嘆號?如果有的話就沒錯了,先選中這個jar,點選右邊的Remove-->點選OK等待幾秒,現在web工程上面的紅色XX是不是沒有了,哈哈。解釋一下:黃色的感嘆號的jar,表示.classpath配置檔案引用了jar,但是實際上lib裡面沒有這個jar

16、使用Intent時出現另一個活動未發現的異常(ActivityNotFoundException)

解決方案:在AndroidManifest.xml中再加一個<activity android:name=".Filelist" android:label="@string/app_name" />

17Fail to connect to camera service

AndroidManifest.xml中新增<uses-permission android:name="android.permission.CAMERA" />

如果還是不行

@Override

        public void surfaceDestroyed(SurfaceHolder holder) {

                // TODO Auto-generated method stub

                mCamera.stopPreview();

               mCamera.release();//加上這句,就OK

                mCamera=null;

        }

18android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

解決方法:將new AlertDialog.Builder(Context context)中的引數用Activity.thisActivity是你的Activity的名稱)來填充就可以正確的建立一個Dialog了。

導致報這個錯是在於new AlertDialog.Builder(mcontext),雖然這裡的引數是AlertDialog.Builder(Context context)但我們不能使用getApplicationContext()獲得的Context,而必須使用Activity,因為只有一個Activity才能新增一個窗體。

19java.io.IOException:您的主機中的軟體中止了一個已建立的連線。

在工作管理員中終止adb服務,關閉手機除錯或者模擬器,重啟就好了。

20java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout

兩個表示位置的屬性不能同時使用,但是有些一起用又沒有報異常,不太瞭解。

android:layout_alignParentTop="true" android:layout_centerHorizontal="true"

21No resource found that matches the given name

在相對佈局中,若是用到android:layout_above屬性,並且其後id之前沒有出現過,那麼需要這樣寫:android:layout_above="@+id/vidAdd_ButtonGroup",多加一個“+”。

22@Override錯誤

Window->Preferences->Java->Compiler.

Compiler compliance level的級別改成1.6,每個工程屬性裡只要預設設定就行了,不要設定specific.

23PANIC: Could not open: C:\Users\Lanyan\.android/avd/SDK2.2.ini

新增android_sdk_home系統變數,其值為想要儲存avd的目錄,例如我放在D:\Program Files\android\avd下。

24Activity has leaked window that was originally added

原因1:重寫onKeyDown時,return super. onKeyDown(int keyCode, KeyEvent event)沒有修改;

原因2:關閉Activity時,沒有關閉AlertDialog造成的。

法一:將return super. onKeyDown(int keyCode, KeyEvent event)改為return false;

法二:@Override

protected void onPause()

{

    super.onPause();

       //關閉對話方塊

    AlertDialog.dismiss();

}

法三:AndroidManifest.xml中,在相應的<Activity>節點中新增

android:configChanges="orientation|keyboardHidden|navigation"

25unable to instantiate application

解決方法1:在AndroidManifest.xml中的application裡的android:name要去掉;

解決方法2:全域性類或者變數私有;

解決方法3package路徑錯誤。

26IllegalArgumentException 'Provider "gps" unknown"

locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);觸發不了LocationManager

加入以下一段引數就好了:

mLocationManager.addTestProvider(LocationManager.GPS_PROVIDER,

"requiresNetwork" == "", "requiresSatellite" == "", "requiresCell" == "", "hasMonetaryCost" == "",

"supportsAltitude" == "", "supportsSpeed" == "",

"supportsBearing" == "", android.location.Criteria.POWER_LOW,

android.location.Criteria.ACCURACY_FINE);

參考:http://hi.baidu.com/mycollection/blog/item/ee700a3895079fecb211c7eb.html

27  已經root手機 DDMS下面無法檢視data目錄,原因許可權不夠

下載軟體root explorer,啟動軟體後,長按data目錄,選擇屬性-》更改許可權,把other許可權全部勾上,搞定。

28 ListView addFooterView不顯示的問題

將addFooterView函式放在 setAdapter之前就好了

28

Eclipse匯入android工程“The import android cannot be resolved”解決辦法

一般是sdk版本選擇不對。

在project- Properties- Android中的Project Build Target裡面勾選相應的SDK即可解決。

轉自:http://www.cnblogs.com/ok-lanyan/archive/2011/10/12/2208378.html