在學(xué)習(xí)Android開(kāi)發(fā)的過(guò)程中遇到了不少的問(wèn)題,所幸的是最終經(jīng)過(guò)上網(wǎng)查詢都得到了解決?,F(xiàn)在將我在學(xué)習(xí)Android開(kāi)發(fā)過(guò)程中遇到的一些問(wèn)題及解決的方法整理如下。
1.R.java不能實(shí)時(shí)更新
問(wèn)題描述:在res文件中新增的變量不能在R.java中實(shí)時(shí)的顯示出來(lái)。
解決方法:選擇菜單欄的“Project”,勾選“BuildAutomatically”選項(xiàng)。
2.LogCat視窗沒(méi)有顯示
問(wèn)題描述:在Eclipse的右下方?jīng)]有顯示LogCat視窗。
解決方法:選擇菜單欄的“Windows”,再選擇“ShowView”,最后再選擇“LogCat”即可。
3.編譯時(shí)提示“androidlibrary projects cannot be launched”錯(cuò)誤的解決方法
問(wèn)題描述:編譯時(shí)提示“androidlibrary projects cannot be launched”錯(cuò)誤
解決方法:選擇菜單欄的“Project”,再選擇“Properties”,在彈出的窗口中選擇“Android”,將islibrary選項(xiàng)前面的勾去掉。
4.在xml中添加EditText控件后提示“Thistext field does not specify an inputType or ahint”錯(cuò)誤
問(wèn)題描述:在xml中添加EditText控件,控件信息如下。
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content">
編譯時(shí),提示“This textfield does not specify an inputType or a hint”錯(cuò)誤。
原因分析:控件中缺少android:hint以及android:inputType信息。android:hint用于設(shè)置EditText為空時(shí)顯示的默認(rèn)文字提示信息。android:inputType用于設(shè)置EditText的文本的類型,用于幫助輸入法顯示合適的鍵盤(pán)類型。
解決方法:在控件中添加android:hint以及android:inputType信息,添加后的控件信息如下。
android:id="@+id/editText"
android:hint="0"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content">
5.警告信息“Hardcodedstring "xxx", should use @string resource”的消除方法
問(wèn)題描述:在xml中添加Button控件,控件信息如下。
android:id="@+id/mButton_mc"
android:text="mc"
android:layout_width="match_parent"
android:layout_height="wrap_content">
編譯時(shí),提示“Hardcodedstring "mc", should use @string resource”警告。
原因分析:在android:text中使用到了字符串mc,應(yīng)該將該字符串定義在String.xml中,然后再通過(guò)調(diào)用String.xml中該字符串的資源名來(lái)使用該字符串資源。這樣做的好處在于可以做到一改全改,并且在支持多語(yǔ)言時(shí)也是很有用處的。
解決方法:在項(xiàng)目目錄下的res-->values-->String.xml中添加字符串mc的信息如下。
mc
然后,再在使用該Button控件的xml中,通過(guò)調(diào)用該字符串的資源名來(lái)使用該字符串,如下。
android:id="@+id/mButton_mc"
android:text="@string/mc"
android:layout_width="match_parent"
android:layout_height="wrap_content">
6.警告信息“Nestedweights are bad for performance”的消除方法
原因分析:在布局進(jìn)行嵌套使用時(shí),父布局與子布局都使用了android:layout_weight,但不是必須使用時(shí),便會(huì)出現(xiàn)如題所示的警告信息。
解決方法:根據(jù)實(shí)際情況,去除子布局中非必須使用的android:layout_weight。
7.啟動(dòng)模擬器時(shí)出現(xiàn)錯(cuò)誤信息“Pleaseensure that adb is correctly locatedat:XXXXX”的解決方法
現(xiàn)象:使用正確的源代碼,在啟動(dòng)模擬器時(shí)出現(xiàn)如下錯(cuò)誤信息“Pleaseensure that adb is correctly located at'D:AndroidSDK4.0android-sdk-windowsplatform-toolsadb.exe' andcan be executed.”
解決方法:將D:AndroidSDK4.0android-sdk-windowsplatform-tools加入到系統(tǒng)環(huán)境變量PATH中。
8.模擬器啟動(dòng)時(shí)一直顯示信息“Waitingfor HOME ('android.process.acore') to belaunched...”的解決方法
現(xiàn)象:模擬器啟動(dòng)時(shí),等很久(5分鐘以上)也啟動(dòng)不了,一直提示“Waitingfor HOME ('android.process.acore') to belaunched...”信息。
解決方法:刪除當(dāng)前的模擬器,重新創(chuàng)建一個(gè)模擬器。
抄來(lái)的經(jīng)驗(yàn)
愛(ài)華網(wǎng)本文地址 » http://www.klfzs.com/a/25101014/226751.html
愛(ài)華網(wǎng)



