Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android常見的異常錯誤

android常見的異常錯誤

編輯:關於Android編程

1.  java.net.SocketException: Noroute to host
重新開一下wifi就可以了.

2.

[plain]
Failed to install xxx.apk on device '040398FE1701701F': Unable to open sync connection! 
java.io.IOException: Unable to open sync connection! 
Launch canceled! 

重新打開usb調試就可以了.

3. [plain
res\values\style.xml:44:error: Error retrieving parent for item: No resource found that matches the given name 'android:WindowTitleBackground' 

Style.xml裡

[html]

<style name="iWindowTitleBackground"parent="android:WindowTitleBackground">    
        <item name="android:background">@drawable/title_bar</item>        
</style> 
將"android:WindowTitleBackground">改為"*android:WindowTitleBackground">就可以了.
參照:http://topic.csdn.net/u/20110830/15/f12f7679-8857-4010-ac6e-88b8f52244e8.html


4. [java]
[2010-03-23 11:57:49 - Poc]Re-installation failed due to different application signatures. 
[2010-03-23 11:57:49 - Poc]You must perform a full uninstall of the application. WARNING: This will remove the application data! 
[2010-03-23 11:57:49 - Poc]Please execute 'adb uninstall com.xue.test' in a shell. 
[2010-03-23 11:57:49 - Poc]Launch canceled! 

刪除手機中的這個工程即可

5.

[java]
12-29 13:59:31.929: ERROR/AndroidRuntime(5594): Caused by: android.app.SuperNotCalledException: Activity {com.test.lthandmap/com.test.lthandmap.poisearch.PoiInfoListActivity} did not call through to super.onResume() 
12-29 13:59:31.929: ERROR/AndroidRuntime(5594):     at android.app.Activity.performResume(Activity.java:3858) 
12-29 13:59:31.929: ERROR/AndroidRuntime(5594):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2127) 
12-29 13:59:31.929: ERROR/AndroidRuntime(5594):     ... 12 more 

重寫onResume()後,super.onResume()刪掉了所導致這個異常,加上就可以了.

6.手機有時候連不上,需要重啟adb

 


7.

[java]
Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 


最近,在android中用代碼動態改變某種布局(組件)的高度時,會遇到如題所示的類轉換異常。上網查了一下,如下所示:
These supply parameters to the parent of this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children.

So basically, if you are adding a view to another, you MUST set the LayoutParams of the view to the LayoutParams type that the parent uses, or you will get a runtime error.

 我是這樣理解的,如果你要將一個view添加到另一個布局中,你必須設定該View的布局參數為其父類所使用的布局參數類型。即要在代碼中動態改變某組件的高度,其布局參數類型應該是其父類所使用的布局參數類型。
view設置了 LayoutParams,他的父控件也需要設置

8.TabHost添加3個及以上tab時報的異常

[java]
Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab content 
at android.widget.TabHost.addTab(TabHost.java:219) 
看TabHost源碼可知mContentStrategy=null,所以改下寫法
原來的寫法

[java]
TabSpec ts1 = tabhost.newTabSpec(TAB1).setIndicator(TAB1); 
        ts1.setContent(new Intent(BottomMenu_ArrowTop.this, TestViewFlipper.class)); 
        tabhost.addTab(ts1); 
改寫後的寫法 [java] view plaincopytabhost.addTab(tabhost.newTabSpec(TAB1) 
                .setIndicator(TAB1) 
                .setContent(new Intent(this,TestViewFlipper.class))); 

9.jni 方法調用錯誤

[java]
2-28 23:02:52.218: ERROR/AndroidRuntime(27159): java.lang.UnsatisfiedLinkError: unimplementedStringFromJNI 
在jni裡沒有unimplementedStringFromJNI方法

10.自定義控件

[html]
03-19 10:40:40.905: ERROR/AndroidRuntime(12911): Caused by: android.view.InflateException: Binary XML file line #244: Error inflating class ScrollTextView 


xml文件的244行,包名錯誤導致的

11.resource not found

[java]
04-13 11:06:00.460: ERROR/AndroidRuntime(25002): android.content.res.Resources$NotFoundException: String resource ID #0x1 

開始覺得很奇怪,clean了一下也不行,後來發現是在textView.setText(position); 裡面應該是string,而當時寫的int
12.viewpager的異常

因sdk升級後viewpager拋出異常

[html]
E/AndroidRuntime(6997): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loader dalvik.system.PathClassLoader[/data/app/cn.cmcc.brower.apk] 

把第三方的包放在項目目錄下的libs裡,右鍵libs包設置 build path 選use as source folder,再把  jar包   add to build path,就ok了

13.連不上手機

[html]
ADB server didn't ACK 
* failed to start daemon * 
關掉360,重啟eclipse,未解決的話,卸載豌豆莢,重啟eclipse

14.IllegalStateException 非法狀態異常

[java]
java.lang.IllegalStateException The specified child already has a parent. You must call removeView() on the child's parent first. 
把一個View實例加入到兩個布局會拋出這個異常,加到第二個布局時new一個view加進去就可以了


15.讓proguard不混淆第三方jar包

[java]
-keep public class 包名.**{*;} 

 


 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved