Android 常见异常处理

Android 常见错误处理

1.could not find "com.baidu.location" class
a.在Android项目根目录下新建一个libs文件夹;
b.把你需要的导入的第三方Jar包复制进这个目录;
c.在libs目录上点右键,选Bulid path  –> Use as source folder

2. sdk manager 无法更新.设置代理(天国网络问题)
set tool ->option
proxy server:mirrors.neusoft.edu.cn
proxy port:80
and check Force http:...... option

3.no system iamge etc. options in sdk manager dialog.
   update Android SDK Tools version
  

4. Show file Explore On rooted device you can do this:
Open cmd
Type 'adb shell'
su
Press 'Allow' on device (可选)
chmod 777 /data /data/data /data/data/com.application.pacakage /data/data/com.application.pacakage/*
Go to the DDMS view in Eclipse

5. **.so' in project 'PythonAPK' cannot be read or is not a valid ZIP file:
  remove it from build path


6. Android export give a “Conversion to Dalvik format failed error1”
  Disable "Build Automatically" on "Project Menu" and rebuild it manually (Right click on project -> Build project),
  then try to export the application again.
  Eclipse seems to conflict with export and compile simultaneously. So every time you need to export an APK,
  disable automatic build. It's safe to use it any other time.


7. 打开res\layout下的文件预览布局页面发现图片已经被替换,
但在模拟器或者真实机器上运行时发现该图片并没有被替换,还是使用的是原来的资源图片。
在开发过程中,由于使用模拟器测试了程序,在首次运行后会将res文件夹下的图片资源文件(如drawable-hdpi、drawable-ldpi和drawable-mdpi)拷贝到bin文件夹下。
在替换资源图片后,eclipse并不清楚是否有图片改变,所以会使用原来bin下的res文件夹中的资源文件进行打包,而图片用的还是第一次eclipse所拷贝进去的文件,
所以当运行程序后会发现替换资源图片在程序中没起作用。
解决方法
只需要把项目bin目录下的res目录删除(可连同bin下生成的.apk、.dex和.ap_等三个文件一并删除),然后再将项目生成apk文件即可。


8. 没签名是不能安装的,系统bin目录下的安装包是自动生成的,是签过名的,默认签名文件在eclipse 中可以选择。
一般都在c盘 user下 C:\Users\admin\.android\debug.keystore
9. Toast .show()仍不显示消息
可查看系统应用设置->消息通知(可能禁止)


10. Unable to execute dex: Multiple dex files define Lcom/mobile/appstore/listjar/sdk/R$anim;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/mobile/appstore/listjar/sdk/R$anim;
Unable to execute dex: Multiple dex files define Lcom/pingan/base/BitmapUtils$AsyncBitmapDrawable
可以很确切的说肯定是 包含了 两个相关的R.anim的资源文件。我的这个例子确实是重复了的,Jar包和引用工程中的资源文件 有重复!所以删掉Jar包中对应的部分就OK!
11.Conversion to Dalvik format failed with error 1解决方法:签名不成功 可能密码错误

12.设置values-land-xhdpi-1824x1200
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();//真实分辨率 宽
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();//真实分辨率 高
        
DisplayMetrics dm = new DisplayMetrics(); 
dm = getResources().getDisplayMetrics(); 
int densityDPI = dm.densityDpi;     // 屏幕密度(每寸像素:120(ldpi)/160(mdpi)/213(tvdpi)/240(hdpi)/320(xhdpi)) 
Toast.makeText(this, "真实分辨率:"+screenWidth+"*"+screenHeight+"  每英寸:"+densityDPI, Toast.LENGTH_LONG).show();


13. DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date());
  正常输出为 yyyy-M-d(2015-3-10)
  在小米四下输出为MMM d,y(Mar 10, 2015)
 

14. 自定义view 报错 android.view.InflateException: Binary XML file line
    构造函数有问题 没有含有属性构造的构造函数(Context context, AttributeSet attrs)

15. context.getResources().getIdentifier(id, "id",context.getPackageName());