微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Android常见错误汇总

Android常见错误汇总

时间:10-08 来源:互联网 点击:

FoundException

出现此类异常时,可以根据 Resource ID到资源类R中找相关的资源。比如0x7f030000,对应的是city_item布局文件,就可以将问题缩小到更小的范围。对于这类运行时找不到资 源,但资源又确实存在的问题,可能的编译打包时出现问题,没有将该资源加入。可修改一下该资源,让编译器重新编译。

还有试一下Project ->Clean一下这个项目 也可以的。

16.交互性的button定义的方法:

首先是准备好按钮不同状态的图片

然后 在res/drawable中定义selector的xml文件

最后Button的background属性中设置

android:id=@+id/btnAdd

android:layout_width=wrap_content

android:layout_height=wrap_content

android:background=@drawable/addbtn_selector/>

17在超级终端中执行程序报错-Permission deny

参照http://android.stackexchange.com ... fo-on-error-message

主要原因是不能在sdcard中执行,直接进入data/目录下面创建文件,然后执行就可以了。

18.从svn导入工程项目有惊叹号

错误提示Archive for required library: 'libs/armeabi/libvudroid.so' in project 'DocumentViewer' cannot be read or is not a valid ZIP file

主要是路径出了问题

解决方法:在project的build-path将外部包(库)的引用删掉就可以了。

19.首次进入带有EditText的Activity不自动弹出软键盘,再次点击才弹出。

只有设置manifest的方法有用,在activity的设置中添加:

[html] view plaincopyprint?

android:windowSoftInputMode=adjustPan|stateHidden

20.Gallery中OnItemClickListener与OnItemSelectedListener的区别

OnItemClickListener:只有单击Gallery中的View才会触发事件,准确的说是当点击之后抬起手的时候触发,滑动不会触发。

OnItemSelectedListener:当Gallery中的View被选中的时候就会触发,Galler初次显示就会触发一次,选中第一个iew,滑动和单击都会触发。

20.从16进制中提取颜色的rgb分量。

主要就是通过位运算来实现。

[java] view plaincopyprint?

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

int INK_COLOR = 0xFF11ef23;

float r = getColorR(INK_COLOR );

float g = getColorG(INK_COLOR );

float b = getColorB(INK_COLOR );

System.out.print(r+ +g+ +b);

}

public static float getColorR(int c)

{

int R = (c 0x00FF0000 )>>16;

return (float) (R/255.0);

}

public static float getColorG(int c)

{

int G =(c 0x0000FF00 )>>8;

return (float) (G/255.0);

}

public static float getColorB(int c)

{

int B = c 0x000000FF;

return (float) (B/255.0);

}

}

21. Eclipse中签名导出apk崩溃,手动签名。

工程没问题,调试也没问题,但打包的时候eclipse会崩溃,解决方法是手动打包。

首先去工程目录下的bin文件夹下找到apk文件,解压后删除META-INF文件夹,重新打包成压缩包,改后缀名为.apk

首先是签名(假设你已经在根目录下生产了密钥keystore):

进入java安装目录/bin文件夹下:

[plain] view plaincopyprint?

./jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore android.keystore ~/Output.apk android

然后是优化,进入sdk的tools文件夹下,运行。

[plain] view plaincopyprint?

./zipalign -v 4 ~/Output.apk Output_realase.apk

当前目录下Output_realase.apk就是打包签名好的apk了。

22.android.view.InflateException: Binary XML file line #异常的解决

创建自定义view的时候,碰到 android.view.InflateException: Binary XML file line #异常,反复研究

后发现是缺少一个构造器造成。

[java] view plaincopyprint?

public MyView(Context context,AttributeSet paramAttributeSet)

{

super(context,paramAttributeSet);

}

补齐这个构造器,异常就消失了.

23.将assets文件夹中的压缩包拷贝到sdcard中(不限大小)

[java] view plaincopyprint?

public static void copyAssetToSdcard(Context c, String assetFile, String destination) throws IOException {

InputStream in = c.getAssets().open(assetFile);

File outFile = new File(destination);

OutputStream out;

Log.v(Try, Try coping.);

try {

if (!(new File(destination)).exists()) {

Log.v(Try, Not exists..);

out = new FileOutputStream(outFile);

copyFile(in, out);

in.close();

in = null;

out.flush();

out.close();

out = null;

}

} catch (E

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top