Android學習筆記03:學習過程中碰到的一些問題及解決方案

來源:互聯網
上載者:User

  在學習Android開發的過程中遇到了不少的問題,所幸的是最終經過上網查詢都得到瞭解決。現在將我在學習Android開發過程中遇到的一些問題及解決的方法整理如下。

1.R.java不能即時更新

  問題描述:在res檔案中新增的變數不能在R.java中即時的顯示出來。

  解決方案:選擇功能表列的“Project”,勾選“Build Automatically”選項。

2.LogCat視窗沒有顯示

  問題描述:在Eclipse的右下方沒有顯示LogCat視窗。

  解決方案:選擇功能表列的“Windows”,再選擇“Show View”,最後再選擇“LogCat”即可。

3.編譯時間提示“android library projects cannot be launched”錯誤的解決方案

  問題描述:編譯時間提示“android library projects cannot be launched”錯誤

  解決方案:選擇功能表列的“Project”,再選擇“Properties”,在彈出的視窗中選擇“Android”,將is library選項前面的勾去掉。

4.在xml中添加EditText控制項後提示“This text field does not specify an inputType or a hint”錯誤

  問題描述:在xml中添加EditText控制項,控制項資訊如下。

     <EditText
         android:id="@+id/editText"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" ></EditText>

  編譯時間,提示“This text field does not specify an inputType or a hint”錯誤。

  原因分析:控制項中缺少android:hint以及android:inputType資訊。android:hint用於設定EditText為空白時顯示的預設文字提示資訊。android:inputType用於設定EditText的文本的類型,用於協助IME顯示合適的鍵盤類型。

  解決方案:在控制項中添加android:hint以及android:inputType資訊,添加後的控制項資訊如下。

     <EditText
         android:id="@+id/editText"
         android:hint="0"
         android:inputType="number"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" ></EditText>

5.警告資訊“Hardcoded string "xxx", should use @string resource”的消除方法

  問題描述:在xml中添加Button控制項,控制項資訊如下。

     <Button 
         android:id="@+id/mButton_mc"
         android:text="mc"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" >            
     </Button>

  編譯時間,提示“Hardcoded string "mc", should use @string resource”警告。

  原因分析:在android:text中使用到了字串mc,應該將該字串定義在String.xml中,然後再通過調用String.xml中該字串的資源名來使用該字串資源。這樣做的好處在於可以做到一改全改,並且在支援多語言時也是很有用處的。

  解決方案:在項目目錄下的res-->values-->String.xml中添加字串mc的資訊如下。

  <resources>
      <string name="mc">mc</string>

  </resources>

  然後,再在使用該Button控制項的xml中,通過調用該字串的資源名來使用該字串,如下。

      <Button 
          android:id="@+id/mButton_mc"
          android:text="@string/mc"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" >            
      </Button>

 6.警告資訊“Nested weights are bad for performance”的消除方法

  原因分析:在布局進行嵌套使用時,父布局與子布局都使用了android:layout_weight,但不是必須使用時,便會出現如題所示的警告資訊。

  解決方案:根據實際情況,去除子布局中非必須使用的android:layout_weight。

7.啟動模擬器時出現錯誤資訊“Please ensure that adb is correctly located at:XXXXX”的解決方案

  現象:使用正確的原始碼,在啟動模擬器時出現如下錯誤資訊“Please ensure that adb is correctly located at 'D:\AndroidSDK4.0\android-sdk-windows\platform-tools\adb.exe' and can be executed.”

  解決方案:將D:\AndroidSDK4.0\android-sdk-windows\platform-tools加入到系統內容變數PATH中。

8.模擬器啟動時一直顯示資訊“Waiting for HOME ('android.process.acore') to be launched...”的解決方案

   現象:模擬器啟動時,等很久(5分鐘以上)也啟動不了,一直提示“Waiting for HOME ('android.process.acore') to be launched...”資訊。 

   解決方案:刪除當前的模擬器,重新建立一個模擬器。

 9.Android模擬器橫屏與豎屏切換

   模擬器啟動後,選中模擬器,按CTRL+F11可以進行Android模擬器橫屏與豎屏的切換。

10.匯入的Android工程@Override報錯

   現象:將網上下載的Android工程源碼匯入Eclipse時,@Override報錯。

   解決方案:在報錯的工程上,滑鼠右鍵選擇 Properties-->Java Compiler-->compiler compliance level中選擇1.6,重新整理工程,就不會報錯了。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.