android 之 异常集合

开发异常:
1、手机空间已经满了。
INSTALL_FAILED_INSUFFICIENT_STORAGE
[2013-12-10 16:28:20 - AndroidBaseDemo] Please check logcat output for more details.
[2013-12-10 16:28:20 - AndroidBaseDemo] Launch canceled!

2、
这个错误是因为你的sdk manager里面没有对应的android sdk build-tools。
解决办法:
方法1、下载安装你工程对应的build-tools。
方法2、将你工程的project-properties文件中的target=***改成你sdk中已经安装的sdk build-tools即可。比如你sdk build-tools的版本为17,就可以将target的值改成target=android-17即可。
project.properties  参数一致;
Unable to execute dex: java.nio.BufferOverflowException


3、版本4.4
添加libs文件夹
project.properties  参数一致;


4、MethodsCompat.java
出错代码: @TargetApi(11)

用新版本sdk,或者删掉这个注解;
4.0.3依然有这个问题,4.1这个问题消失。


5、关闭360手机助手、豌豆荚等软件!!
     D:\Web_soft\android\soft\sdk\platform-tools>adb kill-server
     D:\Web_soft\android\soft\sdk\platform-tools>adb start-server 不再有任何提示说明启动成功!
The connection to adb is down, and a severe error has occured.
Please ensure that adb is correctly located at 'D:\Web_soft\android\soft\sdk\platform-tools\adb.exe' and can be executed.


6、
Android library projects cannot be launched
解决办法如下:
右键工程根目录->properties
左侧择->android
islib 不勾选;

7、在Android工程中加入AIDL文件时,gen目录生成的文件报错
创建了一个AIDL文件,这个时候发现gen目录下自动生成的java文件报错了,内容是里面的一些方法要去掉override,但是去掉之后还是报错。
->java compiler里面的JDK版本从1.5改成了1.6 !!
http://blog.csdn.net/watt520/article/details/10099047

8、生成不了R文件
1)看看 problems 窗口,有没有错误
2)试试右键点项目,选择 Android Tools -> Fix Project Properties

9、Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
xml主文件添加:android:installLocation="preferExternal"


10、Warning: Activity not started, its current task has been brought to the front
你第二次运行程序的时候,你可能测试的程序还在你手机或屏幕上显示着呢吧,点击返回,回到主屏幕,再测试就不会这个问题了。

11、
WARNING: Application does not specify an API level requirement!
Device API version is 15 (Android 4.0)
加入:
<uses-sdk android:minSdkVersion="15"></uses-sdk>

加在<manifest> </manifest> 之间.

12、Android:Error - Case expressions must be constant expressions
This is probably you are using a third_party library, in order to make you develop your application quick and able to use more than one library, the resource id is not defined as           final, so you have to use if/else rather than switch/case.
13、NetworkOnMainThreadException

原因,3以上对访问 网咯安全提高,不能在主线程 直接访问 网路
http://lizhuohuang.iteye.com/blog/1736129

解决1
new Thread(){
    @Override
    public void run()
    {
        HttpClient httpClient = new DefaultHttpClient(); 
        HttpGet httpGet = new HttpGet("http://www.baidu.com/");
        try
        {
            HttpResponse response = httpClient.execute(httpGet);
        }
        catch(Exception e)
        {
            System.out.println("<-------Exception------->");
            e.printStackTrace();
        }      
    }
}.start();


解决 2      StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
         .detectDiskReads()
         .detectDiskWrites()
         .detectNetwork()   // or .detectAll() for all detectable problems
        .penaltyLog()
         .build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
         .detectLeakedSqlLiteObjects()
         .detectLeakedClosableObjects()
         .penaltyLog()
         .penaltyDeath()
         .build());
        super.onCreate(savedInstanceState);

解决方法:在onCreate(Bundle savedInstanceState)方法中调用下面方法【在调用访问网络之前调用】。
/**
* 防止出现NetworkOnMainThreadException 异常处理
*/
private void initStrictMode() {
// 判断操作系统是Android版本3.0以上版本
if(android.os.Build.VERSION.SDK_INT >= 11) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
}

14、INSTALL_FAILED_UPDATE_INCOMPATIBLE
卸载方式有如下几种:
1)优雅式:通过界面 settings-->applications-->manage applications-->找到应用-->application Info-->uninstall 就可以正常卸载应用了。
2)粗暴式 直接到/data/app目录下删除apk
adb shell
cd /data/app
rm xxx.apk
不推荐这种方式,只删除了apk,如果应用还有其他的目录,如数据库目录/data/data/xxx/databases/并没有清理干净,留有隐患。
3)隐藏式:
adb uninstall package-name (这个在adb的帮助文档中没有说明,但可以用)
什么,不知道package-name?看看你的AndroidManifest.xml中有个必须的属性就是package,它所指定的就是package-name。

15、Unable to execute dex: Multiple dex files define
     其实,就是在你的项目下某个文件夹中一个后缀为*.APK的文件,删掉,重启Eclipse即可。
     另外提醒下,一定要重启Eclipse!!
     我查过了网上的解答,说版本不对什么的,我全部检查了更新,发现都是最新版本,不需要任何更新..

     最后解决方法:
我的程序在根目录的libs文件夹中包含了两个jar的包,原因就是这两个包有内容重复或冲突之类的吧(我是这么理解的)
删除一个不需要用的包就可以,我删除了android.support.v4的那个jar
再启动程序就可以了

16、Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace
去除依赖包  Android Dependencies,在eclipse中右键这个文件夹,在Build Path选项中选择  remove it from build path

17、Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
修改一下应用程序描述符:<manifest xmlns:android="http://schemas.android.com/apk/res/android"  package=""  android:installLocation="preferExternal"

18、conversion to dalvik format failed
Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
删除liabiries下面的库:
com.android.ide.eclipse.adt.DEPENDENCIES


猜你喜欢

转载自lixg425.iteye.com/blog/2014970
今日推荐