Fork me on GitHub

android开发中遇到的各种问题收集--不定期更新

 

 

以下问题都是自己在开发中亲身碰到的 ,在这里留个备份,方便下次查阅。

 

1java.lang.IllegalStateException Cannot execute task: the task has already been executed (a task can be executed only once)

非法执行异常,大致是说这个任务已经执行过了,只能执行一个任务

解决:重新new一个任务执行即可。  之前是一开始就初始化任务类 ,在需要执行的地方再用实例对象execute执行

 

2java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fozero.app.interfcalltest/com.fozero.app.interfcalltest.PhoneQueryActivity}: java.lang.NullPointerException

运行时异常,无法开启一个活动Activity  存在空异常

解决:找了很久发现是跳转的目标Activity中初始化UI组件id写错了

 

3java.lang.IllegalStateException: ScrollView can host only one direct child

ScrollView内部只能有一个直接的子元素

解决:将所有的组件放入到Linearlayout布局中,再讲learnlayout布局包含在ScrollView

 

4android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

子线程更新UI 会发生该异常,解决方法是通过借助handle类来更新UI

 

5android.content.res.Resources$NotFoundException: String resource ID #0xd7e

在比如TextViewsetText()方法中向括号中填入了一个int类型的东西啊?我刚刚也遇到了这个问题,一顿好找,终于发现了。对于数字很多时候当做资源的id而不仅仅是数字,比如这里的setText()

TextView.setText()方法有两个:

1、setText(int resid) 这个方法里面的参数是R.string.*,也就是你把字符串已经定义好的;

2、setText(CharSequence text) 这个方法里面的参数可以看做是字符串类型的,这种setText(""+count)方式相当于是把count强制转换成了字符串类型的,或者也可以setText(String.valueOf(count))进行转换,两者都是把int型转换成String型的。

 

6Unable to resolve target 'android-XX

出现 “Unable to resolve target 'android-XX'”,解决办法进入你的android project跟目录,找到此文件 project.properties(default.properties),找到target=android-XX出现此错是因为你的android环境跟此处不对应,那么,你只需要将此处的android版本改成你机器上配置的android版本即可,例如target=android-15

 

7Unable to add window -- token null is not for an application

activity中使用AlertDialog对话框时候出现的错误,这里context使用了applicationcontext

导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。 

解决方法:将new AlertDialog.Builder(Context context)中的参数用Activity.thisActivity是你的Activity的名称)来填充就可以正确的创建一个Dialog了。

 

8android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context  requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

在调用Context.startActivity(intent)的时候报错 ,解决方法:

在前面加上intent.addFlags(FLAG_ACTIVITY_NEW_TASK)或者使用Activity.startActivity(intent)

 

 

 

posted @ 2016-09-16 12:54  fozero  阅读(409)  评论(0编辑  收藏  举报