1. Error parsing XML: unbound prefix
原因之一:拼写错误。例如:android写成androd之类。
原因之二:xmlns没有添加。有的时候,自定了一些view,且新加了一些自定义的命名,那么需要添加声明到根上。如果忘了添加也会报这个错误。
xmlns:calendar=“http://schemas.android.com/apk/res-auto”
2. 没有R文件的错误
检查是否编译了项目。Android studio有时候没有编译就会报出没有R文件的错误。
检查带代码中包名是否正确。有时候从其他地方复制代码过来时连带了包名,也会报出R文件找不到。
检查布局文件是否有语法错误。布局文件有语言错误时也会导致R文件错误。
软件莫名有问题,重建项目试试。
Android studio左上角有个选项,一般我们可能是选的Android模式,选择Packages模式找到你的项目,里面就可以看到R文件了
build--generated-->source-->r-->debug-->R
3.线程中更新主界面异常
e = android.view.ViewRootImpl$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
解决方案:使用handler + sendmessage方式来调用主界面中的方法进行界面刷新
4.android.os.networkonmainthreadexception
在android2.3之后 在主线程中必须使用另一个线程 如handler机制,或者异步任务获取网络数据
如果你访问网络的操作 必须放在主线程中执行,那么 在oncreate()中添加
if (GetVersion.GetSystemVersion() > 2.3) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath()
.build());
}
这样 高版本中也可以在主线程中执行网络操作了
5.java.lang.IllegalArgumentException:
View=com.android.internal.policy.impl.PhoneWindow$DecorView{a964d33 V.E..... R.....ID 0,0-304,223} not attached to window manager
http://www.bubuko.com/infodetail-1120955.html
http://blog.youkuaiyun.com/yuxiaohui78/article/details/38076447
当用户在各个tab page间快速切换的时候,ProgressDialog 使用的context就很不安全。
会遇到调用 dialog.dismiss 和 dialog.show(); 的时候无法attach到Window Manager.
原因:在切换的时候,dialog还没有完成所有的调用,所对应的context已经被destroy或正在destroy。
使用ApplicationContext,(context.getApplicationContext()),这个context无法用于ProgressDialog和Toast。会直接导致crash。
目前的解决方法是,先检查context对应的Activity的状态,如果不可用就停止dialog操作:
private boolean isValidContext(Context c) {
Activity a = (Activity) c;
//a.isDestroyed()方法是android17之后才有的接口
if (Build.VERSION.SDK_INT >= 17) {
if (a.isDestroyed() || a.isFinishing()) {
return false;
} else {
return true;
}
} else {
if (a.isFinishing()) {
return false;
} else {
return true;
}
}
}
6.Android开发 解决AlertDialog中的EditText无法调出输入法的问题
在show之前添加view,之后再window.setContentView,使用同一个布局文件
LayoutInflater inflater=(LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog_store_layout, null);
StoreDialog.setView(layout);
StoreDialog.show();
Window dialogWindow = StoreDialog.getWindow();
dialogWindow.setContentView(R.layout.dialog_store_layout);