开发中所遇到的一些问题与解决方法(1)

21. 2015.2.9  GZIPInputStream抛了IOException
开发中,new GZIPInputStream(urlConnection.getInputStream())
这行代码抛了IOException.在网上看到的一个解决方法( 链接):
InputStream in = url.openStream();
GZIPInputStream zin;
try {//2.3以后
    zin = (GZIPInputStream)in;
} catch (Exception e) {//2.3以前
    zin = new GZIPInputStream(in);
}
解释是: It looks like Gingerbread (2.3) changed the way GZipped streams are handled. Looking at the "magic block" characters indicates that openStream() automatically detects GZipped data and runs it through the correct stream decoder. Of course, if you attempt to run another GZIP decoder on the same stream, that will fail with an IOException.

20:代码里设置相对布局的位置:
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                (int) (TQS.screenWidth / 2.3f), RelativeLayout.LayoutParams.MATCH_PARENT);
 lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
loginContent.setLayoutParams(lp);

19.2014-6-16 设置listView中item的选中状态 :
 convertView.setSelected(selectedPosition == position); 

18.2014-6-13 在线程1,obj.wait();本应在别的线程obj.notify()或obj.notifyAll(),才能唤醒线程1,但在程序中不小心又在线程1唤醒自己了,逻辑错误。

17.2014-6-12 Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView that was originally added here。dialog.hide()引起的,后改为dialog.dismiss(),问题解决,原因尚未细究。

16.2014-6-10 使用contentListView.addFooterView(v, data, isSelectable),有时会报越界异常(HeaderViewListAdapter.isEnale),后改为contentListView.addFooterView(emptyFootView),问题解决了,但原因暂未知。

15.url地址带空格,获取内容出错,解决办法:
  url = url.replaceAll(" ", "%20");

14.
  View convertView = myInflater.inflate(R.layout.quote_transactions_listitem , null);
LayoutParams params =(LayoutParams) convertView.getLayoutParams();
这样得到的params会为null,看View.getLayoutParams()的文档可知,原因是没有attach to root view 。
修改为:
View convertView = myInflater.inflate(R.layout.quote_transactions_listitem ,rootView,falsel);
LayoutParams params =(LayoutParams) convertView.getLayoutParams();
即可解决。

13.需求:android点击空白处软键盘消失。
解决方法:只需要在页面Activity的代码中重写 onTouchEvent事件,即在该页面添加以下代码:
  @Override
    public booleanonTouchEvent(android.view.MotionEvent event) {
      InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
      returnimm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),0);
 }
12.改变系统键盘的Enter键图标:
软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,actionUnspecified,actionNone,actionGo,actionSearch,actionSend,actionNext,actionDone,例如当值为actionNext时enter键外观变成一个向下箭头,而值为actionDone时enter键外观则变成了“完成”两个字。

软键盘的Enter键默认显示的是“完成”文本,通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:

actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.  
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 
actionGo 去往,对应常量EditorInfo.IME_ACTION_GO
actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH    
actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND   
actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT   
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 

11问题描述:ListView上下拉动时,背景颜色为非正常颜色。
解决方法:设置ListView的cacheColorHint属性即可进行控制。

----------------------------------------------------------------------------------------------------------------------------------------------
1.空指:
      有可能空指的地方作出检验,打印LOG日记
      可以作空指针检验工具类

2.联网时,要检查url是否拼写错误,
    用LOG打印出来,看拼写是否有错

3.重要字符串,要打印出来,看是否与预想的一致。字符串两两对应问题。

4.打开流,读写数据库时,用完一定要记着关闭。
  对称编码。

5.注意变量的作用域范围,try-catch-finally

6.项目清单问题。组件没注册,没授权。

7.数据库操作。比如查询,
出错:Bad Request for Field slot 0,-1.numRows=3,numColumns=4
出错原因:String name =cursor.getString(cursor.getColumnIndex("Name"));
      "Name"与表列名不一致引起的问题。

8.线程管理问题:在何时停止工作线程要注意设定

9.条理不够清晰,监控不够准确,注意细节问题,思维要绝对严谨,避免错漏。

10.读db文件进数据库时,文件路径不能包含中文,否则出错(out of memory)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值