android常見錯誤

來源:互聯網
上載者:User

1、Unable to resolve target 'android-2'

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

2、Invalid start tag LinearLayout
main.xml放錯檔案夾了,應該在\res\layout下。

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

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

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

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

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

4、No Space left on device
清除C:\Users\Lanyan\AppData\Local\Temp\AndroidEmulator檔案夾下的tmp檔案

 5、Could 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。

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

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

原因:有兩份相同的AndroidManifest.xml的描述性檔案。

7、java.lang.SecurityException: Requires VIBRATE permission
解決方案:在AndroidManifest.xml中加上一句

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

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

8、Activity not started, its current task has been brought to the front
解決方案:在Eclipse中,“project”-->“clean…”

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

9、ArrayAdapter 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

10、R.java檔案突然不見了

解決方案:右鍵項目-->Build Project

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

10、ScrollView can host only one direct child。
解決方案:需要把所有的子項目放到一個LinearLayout內部或RelativeLayout等其他布局方式。

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

11、emulator: 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即可

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

14、Unable to instantiate activity ComponentInfo
解決方案:更改activity android:name="Acitivity"為activity android:name=".Acitivity"

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

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

問題原因:工程中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" />

17、Fail 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;


}


18、android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
解決方案:將new AlertDialog.Builder(Context context)中的參數用Activity.this(Activity是你的Activity的名稱)來填充就可以正確的建立一個Dialog了。

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

19、java.io.IOException: 您的主機中的軟體中止了一個已建立的串連。
在工作管理員中終止adb服務,關閉手機調試或者模擬器,重啟就好了。

 

20、java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
兩個表示位置的屬性不能同時使用,但是有些一起用又沒有報異常,不太瞭解。

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

21、No 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.

23、PANIC: Could not open: C:\Users\Lanyan\.android/avd/SDK2.2.ini
添加android_sdk_home系統變數,其值為想要儲存avd的目錄,例如我放在D:\Program Files\android\avd下。

24、Activity 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"

25、unable to instantiate application
解決方案1:在AndroidManifest.xml中的application裡的android:name要去掉;

解決方案2:全域類或者變數私人;

解決方案3:package路徑錯誤。

26、IllegalArgumentException '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);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.