异常集锦

来源:互联网 发布:kali linux工具教程 编辑:程序博客网 时间:2024/05/18 02:35

异常一:

问题:

Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled


解决方案:

在tools->android->Enable ADB Integration 前面加上勾选解决

原因:

http://www.tuicool.com/articles/7fQzYvN


异常二:

问题:

Unsupported major.minor version 52.0

解决方案:

将此项目的gradle中如下代码(gradle部分)更改成自己studio的当前版本

<span style="color:#222222;">dependencies {        </span><span style="color:#ff0000;">classpath 'com.android.tools.build:gradle:2.1.0'</span><span style="color:#222222;">        classpath 'swwx.plugin:version-plugin:1.0.0'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }</span>

原因:

高版本在低版本上运行导致


异常三:

问题:

java.lang.RuntimeException: Unable to start activity ComponentInfo ,java.lang.NullPointerException

解决方案:

layout布局文件中标签错误

 <view        android:paddingTop="32dp"        android:layout_width="match_parent"        android:layout_height="1dp"        android:solidColor="#DBDBDC"        />

正确应该为大写的View:

<View        android:paddingTop="32dp"        android:layout_width="match_parent"        android:layout_height="1dp"        android:solidColor="#DBDBDC"        />



异常四:

问题:

should use app : showAsAction with the app compact library with xmlns:app="http://schemas.android.com/apk/res-auto"


解决方案:

在最外层menu标签处加上  xmlns:app="http://schemas.android.com/apk/res-auto

showAsAction前面的标签android更改为app



异常五:

问题:

编译报错

Cannot resolve symbol 'checed'

解决方案:

去掉不小心导入的:

import static android.databinding.tool.util.GenerationalClassUtil.ExtensionFilter.BR;

异常六:

问题:

运行崩溃 

java.lang.RuntimeException:Unable to instantiate activity ComponentInfo{DemoActivity}:java.lang.NullPointerException


解决方案:

将findViewById放到setContentView(R.layout.activity_demo)后面

原因:


异常七:

问题:

在java中获得xml中EditText的值为空

原因:

1)在获取EditText的内容时,本身就还没有内容

解决方案:

需要在页面中填写实际内容后方可取值

异常七:

问题:

在java中获得xml中EditText的值为空

原因:

1)在获取EditText的内容时,本身就还没有内容

解决方案:

需要在页面中填写实际内容后方可取值


异常八:

问题:

is not an enclosing class

原因:

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public class A {  
  2.     public class B {  
  3.           
  4.     }  
  5. };  

需要实例B类时,按照正逻辑是,A.B ab = new A.B();

那么编译器就会出现一个错误--"is not an enclosing class"

再翻看相关的java代码,发现原来写法出错了!正确的做法是

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. A a = new A();  
  2. A.B ab = a.new B();  

解决方案:

没有静态(static)的类中类不能使用外部类进行.操作,必须用实例来进行实例化类中类




异常九:

问题:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first

原因:

新的activity没有在manifest中进行注册









0 0