Android開發常見問題及解決方案小結
1.ActivityManager: Warning: Activity not started, its current taskhas been brought to the front
說明:模擬器中已經有一個執行個體在運行。
解決方案:退出模擬器中啟動並執行程式,再次運行即可解決。
2.Nogrammar constraints (DTD or XML schema) detected for the document
說明:在編輯器中看到像這樣關於缺少文法約束(DTD 或 XML 結構描述)的警告,儘管忽略這些警告。
解決方案:windows ->preferences -> xml -> xml files -> validation -> Indicate when nogrammar is specified: 選擇Ignore即可。
3. R.java:no such file or directory
說明:R類不存在。
解決方案:Windows->Preference->Java->BuildPath中,將Folders改為選中Projects即可。
4.res\layout\*.xml:Invalid file name: must contain only [a-z0-9_.]
說明:樣式XML的檔案名稱起的不符合要求。檔案名稱中只能是小寫英文字元、數字、"_"或者"."。
5.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
說明:這樣的問題主要是簽名衝突造成的,比如你使用了ADB的debug許可權簽名,但後來使用標準sign簽名後再安裝同一個檔案會出現這樣的錯誤提示。
解決方案:卸載原有版本再進行安裝,而adb install-r參數是無法解決這個問題。
6.Android程式為什麼沒有退出設計。
答:Google Android平台在設計程式聲明周期上比較特殊,可能是考慮到第二次載入時保證速度的原因而沒有強制加入記憶體釋放問題,所有的資源回收由Dalvik GC自動完成,所以在設計開發時一定要注意Activity和 Service類的生命週期問題,顯示在最上層的視窗將有最高的優先順序,當Android作業系統記憶體不夠用時自動將會根據曆史棧按優先順序強制殺掉進程。
7.EmulatorControl GPS軌跡發送按鈕有時會變灰不可點。
答:重啟Eclipse。
8.android.content.ActivityNotFoundException:Unable to find explicit activity class {XXX}
答:在AndroidMainifest.xml中聲明一下XXXActivity,如:<activity android:name = “.XXXActivity” >
9.模擬器打不開,提示項目有錯誤(Your project contains error(s)...)
答:也許項目裡沒有錯誤,但仍會出現這種提示,重新整理重啟仍然解決不了的話,就刪除項目(不用選擇把檔案刪除),重新匯入一下。
10.Eclipse報錯"No embedded stylesheetinstruction for file"的解決方案
21:11:57,015 INFO [main] Main -javax.xml.transform.TransformerFactory=null
21:11:57,015 INFO [main] Main - java.endorsed.dirs=D:\ProgramFiles\Java\jre6\lib\endorsed
21:11:57,031 INFO [main] Main - launchFile:E:\JavaWebAPP\.metadata\.plugins\org.eclipse.wst.xsl.jaxp.launching\launch\launch.xml
21:11:58,453 FATAL [main] Main - No embedded stylesheet instruction for file:file:/E:/JavaWebAPP/myApp/config.xml
org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embeddedstylesheet instruction for file: file:/E:/JavaWebAPP/myApp/config.xml
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:225)
atorg.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:186)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:73) Causedby: org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embeddedstylesheet instruction for file: file:/E:/JavaWebAPP/myApp/config.xml
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:214)
... 2 more
分析:因為編輯介面顯示的是一個xml檔案,所以點Run按鈕時,Eclipse並不是去Project中尋找main()方法來運行,而是“運行”當前的xml檔案,至於是在幹什麼我也不清楚,結果也很簡單,因為你的xml不符合Eclipse的“運行”要求,所以它自然要報錯了。
eclipseseems to want to "run" whatever you have selected. go knows what it'sdoing when you try to run something like strings.xml, but it fails andgenerates a .out file ... which then corrupts your android project becauseandroid doesn't understand all the .out files laying all of the place.
解決方案:運行Project時不要把編輯介面放在xml上,或者,手動選擇main()方法所在的類,點"Run"。
removeall of the *.out.* files in your project. when you run, click on
the project (top level) in the package browser (left pane) first, and
ensure that you are doing "run as" an android application.
11.出現An internal error occurredduring: "Launching New_configuration". Path for project must haveonly one segment.提示錯誤。
在Eclipse中按照如下操作
Project -> Properties ->Run/Debug Settings:
1. select "Launching New_configuration"
2. Delete
3. OK
12.在DOS 下輸入 android list targets 會出現android不是內部或外部命令
找到設定環境變數的地方,然後在 path 中加入
;C:\Android\android-sdk\tools;C:\Android\android-sdk\platform-tools
13.Error parsing XML: unboundprefix.
< TextView
android:layout_width="wrap_content"
andriod:layout_height="wrap_content"
android:text="@string/main_title"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp"
/>
The reason is the word "andriod" in the 3rd lineis wrong, it should be "android".
At first I was crazy because I could not find out thereason. I should be more carefull !
14.AndroidFailed to install on device ‘emulator-5554′: timeout 問題的解決方案
eclipse -> window -> Preferences -> Android-> DDMS -> ADB connection time out(ms).把這個時間設定的長一些,預設是5秒,我改成20秒就ok了。然後重啟模擬器,這樣就不用每次重啟模擬器了~