android 中遇到的异常汇总

来源:互联网 发布:克里斯.邓恩数据 编辑:程序博客网 时间:2024/05/16 11:06

http://blog.csdn.net/jason0539/article/details/11699647


1.  错误:Android.content.res.Resources$NotFoundException: String resource ID #0x1

  原因:

  一般发生在参数 int resId 错误,你把String赋值给int的resId,所以编译器找不到正确的resource于是报错。

  解决方法:

  方案一:

count.setText(String.valueOf(incall.getCount())); 

  方案二:

    count.setText(incall.getCount() + "");  


2. 错误:toast提示异常: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()。

  原因:toast只能在主线程中弹出,子线程中弹出Toast代码如下:

 Handler handler = new Handler(Looper.getMainLooper());                    handler.post(new Runnable() {                        public void run() {                            //放在UI线程弹Toast                            Toast.makeText(getApplicationContext(),"子线程弹出Toast",Toast.LENGTH_LONG ).show();                        }                    });


3.错误:listview的数据更新失败

   listview使用自定义的适配器,传入的数据源是ArrayList。当更新数据的时候,使用adapter.notifyDataSetChange 数据未变化。 

   解决方案:数据源更新的时候不使用“=”,数据更新方案:

list.clear();list.addAll(varlist);

4.代码中获取的appCode和AndroidManifest文件中的版本不一致。

原因:在build.gradle文件中的版本号和manifest文件中的版本号不一致。保持两者一致,或者删除build.gradle中的版本号

http://blog.csdn.net/duantihi/article/details/50601870

原创粉丝点击