当前位置: 代码迷 >> Android >> Android:学习笔记(2)
  详细解决方案

Android:学习笔记(2)

热度:38   发布时间:2016-04-27 23:16:22.0
Android:学习笔记(二)

在学习过程中会遇到一些问题,并解决它。

1、问题一

Failed to install ListView.apk on device 'emulator-5554': timeout

解决办法:

window->preferences->Android->DDMS->ADB connection time out (ms): 将这个值设置的大一些,默认为5000,设置成200000

2、问题二

android.os.NetworkOnMainThreadException

解决办法:

    版本问题,在4.0之后在主线程里面执行Http请求都会报这个错,网上查到相应的解决方案,在onCreate()中添加下面两句代码即可: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());       StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

3、问题三

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

解决办法:

TextView 在使用方法是,添加入setText的不是String类型ageText.setText(userinfo.getUser_age());Int-->string方法一:ageText.setText(userinfo.getUser_age()+"");方法二:在UserInfo中定义User_age是定义为Integer,然后ageText.setText(userinfo.getUser_age()。toString());

4、问题四

java.lang.IllegalArgumentException: column '_id' does not exist

解决办法:

这个是在使用SimpleCursorAdapter 适配器时,适配器在组装数据的时候,Cursor数据中没有"_id"这一列。关于例子,[适配器部分代码可以看到](http://blog.csdn.net/qq_17326933/article/details/48015251)将数据中添加"_id"列,例如:Cursor cursor = db.rawQuery("select **user_id as _id** ,user_name as name,user_age as age from user_info",null);

下图是SimpleCursorAdapter的父类CursorAdapter源码中的解释

这里写图片描述

版权声明:本文为博主原创文章,未经博主允许不得转载。

  相关解决方案