开发问题笔记

来源:互联网 发布:mssql数据库备份分离 编辑:程序博客网 时间:2024/06/05 12:53
1. VideoView在设置match_parent的情况下无法全屏显示

重写VideoView的onMeasure方法。

@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {    int widthSize = MeasureSpec.getSize(widthMeasureSpec);    int widthMode = MeasureSpec.getMode(widthMeasureSpec);    int heightSize = MeasureSpec.getSize(heightMeasureSpec);    int heightMode = MeasureSpec.getMode(heightMeasureSpec);    if (widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY) {        setMeasuredDimension(widthSize, heightSize);    } else {        super.onMeasure(widthMeasureSpec, heightMeasureSpec);    }}


2. 在xml中添加自定义控件时,需要这个(记录一下,省的每次找):
xmlns:app="http://schemas.android.com/apk/res-auto

3. ContentResolver.update()时,报NullPointerException

答:update时,Uri与ContentValu都不能为空

    /**     * Update row(s) in a content URI.     *     * If the content provider supports transactions the update will be atomic.     *     * @param uri The URI to modify.     * @param values The new field values. The key is the column name for the field.                     A null value will remove an existing field value.     * @param where A filter to apply to rows before updating, formatted as an SQL WHERE clause                    (excluding the WHERE itself).     * @return the number of rows updated.     * @throws NullPointerException if uri or values are null     */    public final int update(@NonNull Uri uri, @Nullable ContentValues values,            @Nullable String where, @Nullable String[] selectionArgs) {

4. List删除元素方式抛异常

结论:ArrayList使用Iterator方法删除,CopyOnWriteArrayList使用remove方法删除。

原因:CopyOnWriteArrayList线程安全,他的Iterator返回的是数据的一份拷贝,可看源码说明。

    ArrayList在for-each进行删除时容易出现问题,建议使用Iterator。


5. aar中有so,但是找不到

现象:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.qihancloud.librarydemo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.qihancloud.librarydemo-1/lib/arm, /data/app/com.qihancloud.librarydemo-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libuvcNative.so"
                                                                                at java.lang.Runtime.loadLibrary(Runtime.java:367)                                                                                at java.lang.System.loadLibrary(System.java:1076)

原因:当项目引用多个aar包,且aar中包含so库时,如果两个aar的so的文件夹不同,如‘arm’、‘armeabi-v7a’、‘x86’等,则会出现这个问题。

解决:从错误日志中,找到需要的文件包,添加相应的so库即可。如上面错误中,添加‘armeabi-v7a’文件夹。