在Android開發android項目遇到的常見問題整合

來源:互聯網
上載者:User

標籤:android   support   noactionbar'   cannot   parent   

常見問題


1. 匯入SupportV7Demo編譯報錯,控制台提示

[2016-05-26 16:17:22 - Support7Demos] D:\workspace\xa27_advanced\Support7Demos\res\values\styles.xml:26: error: Error retrieving parent for item: No resource found that matches the given name 

‘Theme.AppCompat.Light.NoActionBar‘.

原因:需要依賴support\v7\appcompat庫

解決:匯入AppComapt庫

提示:一定要選擇拷貝

    

2. 庫項目不能運行

    

3. Utils cannot be resolved找不到

4. error: Error retrieving parent for item: No resource found that matches the given name  ‘android:Widget.Material.ActionButton‘.

原因:Material

背景:Android 5.0新增的設計風格

解決:改為使用Android6.0編譯

5、 

  dependency list:依賴列表

  原因:supportV4.jar有多個版本,它們之間有衝突

  解決:將項目和庫中的supportV4.jar改為同一個版本,或者刪除項目中的supportV4.jar

sdk\extras\android\m2repository\com\android\support\support-v4

    

2. 將清單中最低版本號碼改為9  

  

Call requires API level 11 (current min is 9): android.app.Activity#onCreateView

原因:分析發現沒有使用onCreateView()方法,eclipse編譯問題

解決:clean

規避:

    

 4. [2016-05-27 12:00:44 - EX05_Actionbar最低相容4.0] ActivityManager: Warning: Activity not started, its current task has been brought to the front

原因:運行不同的項目,eclipse的bug

解決:clean

5. 清單中最低版本號碼是9,菜單xml檔案中的shouAsAction有警告

Attribute "showAsAction" is only used in API level 11 and higher (current min is 9)

原因:使用了高版本的xml屬性

解決:改為使用appcompatV7的屬性

術語:命名空間  xmlns

6. Type mismatch: cannot convert from BlankFragment to MyFragment

    類型不符    

    ft對象在commit後失效,下次使用需要重新建立

8. 在Fragment布局中使用onClick屬性,運行時FC

  原因:運行時系統會到Activity中尋找onClick屬性值對應的方法

不會在Fragment中找方法

解決:在Fragment的布局中不要使用onClick

NullPointerException異常

Cause by緊跟著自己的代碼,說明當前代碼中某個對象為null

    例如  

    

Causeby之後不是自己的代碼,說明當前代碼觸發了其他代碼null 指標

 原因是傳入某個參數為null

 例如:  

   

9. id對應的布局沒有在contentView中

    12. 在布局中添加toolbar,編譯出錯

   error: Error parsing XML: unbound prefix

    

    原因:未定義命名空間

    解決:聲明命名空間

    xmlns:appv7="http://schemas.android.com/apk/res-auto"

13. Class requires API level 3 (current min is 1): android.widget.HorizontalScrollView

清單中最低sdk配置要高於3

原因:Android Studio的項目,最低版本號碼不在資訊清單檔中

14. 

開源庫拋異常,原因是傳入了沒有設定配接器物件的pager

解決:先設定pager的適配器,再傳入

15. 

    

沒有重寫getPageTitle()方法

16. 

    

    原因:eclipse的bug

解決:clean

  注意:在xml布局檔案中使用,必須重載兩個參數的構造方法     

                  

        讓自訂控制項動起來

           

      注意:如果是在子線程重新整理控制項,不能調用invalidate()方法

       需要調用postInvalidate()

    17.添加熱門城市

            

    ListView在添加HeadView時,必須先添加,然後在設定適配器

  解決ListView中嵌套GridView衝突問題

  ScrollView嵌套GridView  ScrollView嵌套ListView

  使用庫中的GridView4ScrollView

                        

5. JDK1.7新增文法,泛型

    

18. 拷貝SupportV7Demo的ActionBarWithDrawerLayout類編譯報錯

   The import android.support.v7 cannot be resolved

19. 拷貝SupportV7Demo的ActionBarWithDrawerLayout類運行FC

原因:如果Activity繼承了AppCompatActivity,主題必須使用Theme.AppCompat開頭的主題

    

解決:修改清單中配置的主題

 

1. 解決產生的POJO編譯錯誤

1) 項目libs目錄中拷貝一個gson.jar,或者依賴lib_yuchen0428庫

   

2) ctrl + 1,添加包名

    

3) 刪除匯入

4) 刪除

解析json對象,但下載的是jsonarray字串

2. 解析jsonarray對象,但下載的是json字串

    

3. [2016-06-01 12:03:51 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/android/volley/VolleyError;

[2016-06-01 12:03:51 - EX33_使用gson包解析json] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/android/volley/VolleyError;

原因:多次使用了同一個庫,庫衝突

解決:刪除項目中使用的重複庫之一

4. 使用UIL運行時FC

init  initial   initialization   初始化

原因:使用之前沒有配置

5. 

原因:使用jsonschema2pojo工具產生的JAVA類,可能某些欄位的類型不對,需要修改

解決:根據實際類型修改POJO

 5. 為IntentService的子類添加了有參數構造方法,運行時FC

    

 

 

1. 多個含有so檔案的開放介面公用衝突問題

將libs中缺少的目錄補全,so檔案從armeabi-v7a拷貝

. 在.so中沒有被JAVA代碼調用的方法

3.在某個so目錄中找不到so檔案

 

4. 繼承IntentService時編譯報錯   Implicit super constructor IntentService() is undefined. Must explicitly invoke another constructor

 

5. 為IntentService的子類添加了有參數構造方法,運行時FC

5.為IntentService的子類添加了有參數構造方法,運行時FC

    

 

 


本文出自 “怎樣打好java基礎” 部落格,請務必保留此出處http://xiezhengping.blog.51cto.com/8272111/1794387

在Android開發android項目遇到的常見問題整合

聯繫我們

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