Android错误

来源:互联网 发布:云计算和大数据年收入 编辑:程序博客网 时间:2024/06/07 03:24


(1)

Android Studio aapt.exe finishedwith non-zero exit value 1 

Execution failed for task ':app:processAllDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '......\build-tools\23.0.0\aapt.exe'' finished with non-zero exit value 1

解决方案:

一、检查build.gradle中设置的版本

compileSdkVersion 23

buildToolsVersion "23.1.1"

确保以上两个key的value前缀版本一直,此例中设置的是23。

确保buildToolsVersion填写的值对应sdk/build-tools/23.1.1 的此目录存在。



二、检查Gradle版本
gradle/wrapper/gradle-wrapper.properties
distributionUrl=https \://services.gradle.org/distributions/gradle-2.8-all.zip


(2)

android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>

我遇到的情况是:


上面这个图在主页,之后没有button点击进入不同的页面,页面中基本都是有一张或者几张比较大的背景图片(页面并没有其他操作,所有的内容,UI做在了图片上),子页面通过back键返回该页面,我在短时间多次进入子页面,出子页面,会出现Android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>这个错误,同时伴随OOM错误。


我以为back键返回的时候,系统应该会杀死了那些子Activity,

怎么可能会内存不足。

于是上网找答案,在亲爱的stackoverflow上发现了大神的评论,(大神请移步:http://stackoverflow.com/questions/7536988/android-app-out-of-memory-issues-tried-everything-and-still-at-a-loss/7576275)

其实是因为我们并没有手工回收资源,换句话说,Java的垃圾回收机制并没有那么的聪明,我们finish掉了,但里面相关的资源他未必回收。有可能他自以为很聪明的留下来等着我们下次使用。所以我们需要在onStop的方法中手动释放imageView这样的大型资源。

大神的写法,特此记录一下

@Overrideprotected void onStop() {    releaseImageView(image1);    super.onStop();}private void releaseImageView(ImageView imageView) {    Drawable d = imageView.getDrawable();    if (d != null)        d.setCallback(null);    imageView.setImageDrawable(null);    imageView.setBackgroundDrawable(null);}




(3)file.createNewFile()发生IO异常


如下代码:

String path3="/mnt/sdcard/ad/gong/news/20160627/4a15be457393ee71aa7b9b6005dc4c72.png";File file3=new File(path3);if(!file3.exists()){    try {        file3.createNewFile();    } catch (IOException e) {        e.printStackTrace();    }}


运行结果后,会发生IO异常:



很不明白为什么会IO异常,file.createNewFile()这句代码创建成功就返回true,创建失败是false,怎么会IO呢?

后来加了一句代码就不会出现IO异常了,

try {    file3.getParentFile().mkdirs();    file3.createNewFile();} catch (IOException e) {    e.printStackTrace();}

以前记得,创建file文件的时候,直接给一个路径就可以了,不用管这个路径下面的文件夹是否存在,不存在系统会自己创建的,但是现在不可以了,我测试了一下,path中有一个以上的文件夹不存在,都会报IO异常,可能是现在版本问题吧,以后一定要记住

file3.getParentFile().mkdirs();




(4)Permission Denial: starting Intent 解决办法


在一个app里面启动另一个app里面的某个activity,代码如下:

  Intent intent = new Intent(Intent.ACTION_MAIN);        intent.putExtra("id", id);        ComponentName cn = new ComponentName(packageName, activityName);        intent.setComponent(cn);        startActivity(intent);
结果提示错误:

Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cmp=com.yunlv.redpackageactive/.activity.GetRegisterActivity (has extras) } from 


启动器没有权限启动这个Activity,解决方法是对Activity加上 MAIN intent-filter。于是在AndroidManifest.xml中这个Activity里加上:           

[html] view plain copy
  1. <intent-filter>  
  2.                 <action android:name="android.intent.action.MAIN" />  
  3.    
  4. </intent-filter>  

成功





0 0