android开发错误记录

eclipse /java
xampp(apache+php+mysql)随时更新

错误1:org.json.JSONException: Value <br of type java.lang.String cannot beconverted to JSONObject
原因一般是php脚本有错误,执行出问题,返回的并不是json对象。查看xampp control panel 的php_error_log 排除错误

错误2:Value [251056,0,"user"] at 0 of type org.json.JSONArray cannot be converted to JSONObject
原因:$row=$result->fetch_row();//[251056,0,"user"],没有包括字段$output[]=$row; print(json_encode($output));
修改为: $row=$sresult->fetch_assoc(); [userid:251056,money:0,role:"user"],包括了字段 $output[]=$row; print(json_encode($output));

错误3:javax.crypto.BadPaddingException: pad block corruptedAES解密的时候抛出异常。
解决:
private static byte[] getRawKey(byte[] seed) throws Exception
{ KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
return raw;
}
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
修改为:
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");

错误4 :Unable to find explicit activity class {xxxxxx}; have you declared this activity in your AndroidManifest.xml?
解决:在AndroidManifest.xml的application段添加声明:<activity android:name=".ActivityName" />4大基本组件都需要注册才能使用,
每个Activity、service、Content Provider都需要在AndroidManifest文件中进行配置。AndroidManifest文件中未进行声明的activity、服务
以及内容提供者将不为系统所见,从而也就不可用。而broadcast receiver广播接收者的注册分静态注册(在AndroidManifest文件中
进行配置)和通过代码动态创建并以调用Context.registerReceiver()的方式注册至系统。需要注意的是在AndroidManifest文件中进行
配置的广播接收者会随系统的启动而一直处于活跃状态,只要接收到感兴趣的广播就会触发(即使程序未运行)。

错误5:l解析后台xml文件, 中文出现乱码
xml文件指定了格式:<?xml version="1.0" encoding="utf-8"?>
前台也是用utf-8,还是现实乱码。
解决:用dreamware创建utf-8格式的xml文件。之前是创建记事本文件然后再改后缀,虽然在里面也写了<?xml version="1.0" encoding="utf-8"?>这句,不过显然保存不是按照utf-8格式。


错误6:context.getExternalCacheDir() 返回null
解决:无外部存储写权限。AndroidManifest.xml增加: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>。
错误7:在sk卡中存储apk可以正常安装,可是在内部存储中安装apk时出现了parse error的问题。
代码如下:
File file = new File(DiskCacheDir,"apptest.apk");
FileOutputStream fos = new FileOutputStream(file);
// write the .apk content here ... flush() and close()
// Now start the standard instalation window
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
startActivity(intent);
原因是对文件没有访问权限。
两种解决办法:
1、在存储时给文件设定权限。这种方案问题是设定了之后别的应用也可以访问它了。
String fileName ="tmp.apk";
FileOutputStream fos = openFileOutput(fileName,MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
// write the .apk content here ... flush() and close()
/ Now start the standard instalation window
File fileLocation =newFile(context.getFilesDir(), fileName);
Intent intent =newIntent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(fileLocation),"application/vnd.android.package-archive");
context.startActivity(intent);

2、在使用文件之前更改文件权限
String chmodCmd = "chmod 666 " + apkfile.getAbsolutePath();
try {
Runtime.getRuntime().exec(chmodCmd);
} catch (Exception e) {
}
Intent i = new Intent(Intent.ACTION_VIEW);
String filePath = "file://" + apkfile.toString();
i.setDataAndType(Uri.fromFile(apkfile),"application/vnd.android.package-archive");
mContext.startActivity(i);

错误8:apk更新版本后安装失败,原因是老的没有删除,key已经存在。新的版本要使用另一个key。

错误9:getEntry failing because entryIndex 18 is beyond type entryCount 11
点击AlertDialog取消后报的错误。
解决:project->clean.可能因为之前整理过工程文件。

错误10:嵌入youmi广告sdk,出现错误java.lang.NoClassDefFoundError: net.youmi.android.AdManager
解决:按照网上的说法,升级了jdk跟youmi sdk的一致,然后又build path等一些列设置,都没有解决问题。最后是升级了
build-tools到版本22,解决了问题。
build-tools下载地址:http://www.androiddevtools.cn/ 。

错误11:ArrayAdapter requires the resource ID to be a TextView
解决:list.setAdapter(new ArrayAdapter<String>(this,R.layout.exchangelist_item,data));
exchangelist_item 这个xml文件仅能有一个textview。连Layout也不能有。否则会报错:ArrayAdapter requires the resource ID to be a TextView
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/online_user_list_item_textview" >
</TextView>

错误12:listview item点击事件失效。其中class ScrollAdapter extends SimpleAdapter来实现水平滑动。
解决:item的xml文件最顶层增加:candroid:descendantFocusability="blocksDescendants" 。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="50dip"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants" >

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值