Android疑难问题解决记录

以下记录的是个人遇到的问题及相应的解决方法,仅供参考

开发环境:Android studio


情况一:
描述:写Android app时,出现activity对应的layout预览图所显示的activity是有标题栏的,但是运行该app,无论是模拟器还是真机,却出现没有了标题栏的情况,而自己没有特地隐藏标题栏。
解决:此时出现标题栏消失可能是因为activity继承是Activity而不是AppCompatActivity,而我们在创建app之初,AS默认是继承AppCompatActivity,AndroidManifest.xml文件里对应的theme则是

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

情况二:
描述:多个Fargment使用同一layout ID,在进行来回切换操作时出现“java.lang.IllegalStateException: commit already called”的错误。
解决:由于本人将FragmentTransaction变量定义为全局变量,导致只能commit一次,所以只要将FragmentTransaction变量定义为局部变量即可。


情况三:
描述:使用FragmentTransaction的replace方法时出现错误:

'replace(int, android.app.Fragment, java.lang.String)' in 'android.app.FragmentTransaction' cannot be applied to '(int, com.jarwell.learnactionbar.ContentFragment, java.lang.String)'

解决:此种情况发生在ContentFragment所继承的Fragment是android.support.v4.app.Fragment,而FragmentTransaction对象所导入的包是android.app.FragmentTransaction,由此出现不兼容的情况。据此只要统一导入包的类型即可,譬如可以分别:import android.app.Fragment和import android.app.FragmentTransaction


情况四:
描述:如何添加assets文件夹?
解决
首先,在“工程名.iml”文件里的configuration标签下添加以下代码:

<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets"/>

然后,在main文件夹里新建一个子文件夹并命名为assets,到此完成,之后就可以往里面添加文件了。


情况五:
描述:在JSON解析时出现了以下错误日志:

08-31 15:36:59.369 13195-13195/? E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
08-31 15:36:59.370 13195-13195/? E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
08-31 15:36:59.381 13195-13195/? E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.382 13195-13195/? E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.382 13195-13195/? E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.383 13195-13195/? E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.386 13195-13195/? E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.391 13195-13195/? E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.393 13195-13195/? E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.395 13195-13195/? E/dalvikvm: Could not find class 'android.transition.TransitionManager', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.402 13195-13195/? E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.410 13195-13195/? E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.412 13195-13195/? E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.416 13195-13195/? E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.jarwell.learnjson.MainActivity.access$super
08-31 15:36:59.477 13195-13195/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
08-31 15:37:32.664 518-795/? E/FWKEXT: Enter GetCurrentOP

解决:出现以上情况,是因为代码所调用的一些方法只能在较高的API level(高于minSdkVersion)上使用,而调试用的机子或模拟器所用的SDK Version小于该API level。如日志第一行提示中的ArrayMap,通过查看Android官方API可得到如下信息:

Added in API level 19

而本人的project的build.gradle如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.jarwell.learnjson"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
}

其中所使用的minSdkVersion17targetSdkVersion24,而run app的机子对应的API level恰好是17(17<19<24),因此出现了以上的错误日志信息,尝试用level为19以上的机子或模拟器则运行正常。

发布了6 篇原创文章 · 获赞 1 · 访问量 3万+
展开阅读全文

Android连接adb后弹出的log信息中的问题

10-13

安卓手机连接adb后打印出的log信息,这些信息是什么意思?怎么修复?严重吗?: W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/app/ActivityCompat21$SharedElementCallbackImpl; (57) W/dalvikvm(12355): Link of class 'Landroid/support/v4/app/ActivityCompat21$SharedElementCallbackImpl;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/app/FragmentTransitionCompat21$1; (1845) W/dalvikvm(12355): Link of class 'Landroid/support/v4/app/FragmentTransitionCompat21$1;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/app/FragmentTransitionCompat21$3; (1845) W/dalvikvm(12355): Link of class 'Landroid/support/v4/app/FragmentTransitionCompat21$3;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/hardware/fingerprint/FingerprintManagerCompatApi23$1; (185) W/dalvikvm(12355): Link of class 'Landroid/support/v4/hardware/fingerprint/FingerprintManagerCompatApi23$1;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/media/VolumeProviderCompatApi21$1; (226) W/dalvikvm(12355): Link of class 'Landroid/support/v4/media/VolumeProviderCompatApi21$1;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/media/session/MediaControllerCompatApi21$CallbackProxy; (227) W/dalvikvm(12355): Link of class 'Landroid/support/v4/media/session/MediaControllerCompatApi21$CallbackProxy;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/media/session/MediaSessionCompatApi21$CallbackProxy; (231) W/dalvikvm(12355): Link of class 'Landroid/support/v4/media/session/MediaSessionCompatApi21$CallbackProxy;' failed W/dalvikvm(12355): Link of class 'Landroid/support/v4/view/ViewCompatLollipop$1;' failed W/dalvikvm(12355): Link of class 'Landroid/support/v4/widget/DrawerLayoutCompatApi21$InsetsListener;' failed W/dalvikvm(12355): method Landroid/support/v7/internal/widget/ListViewCompat;.lookForSelectablePosition incorrectly overrides package-private method with same name in Landroid/widget/ListView; W/dalvikvm(12355): Unable to resolve superclass of Lcom/umeng/fb/push/b$1; (6376) W/dalvikvm(12355): Link of class 'Lcom/umeng/fb/push/b$1;' failed W/dalvikvm(12355): Link of class 'Lorg/apache/harmony/awt/datatransfer/DataProxy;' failed W/dalvikvm(12355): Unable to resolve superclass of Lorg/apache/harmony/awt/datatransfer/NativeClipboard; (7155) W/dalvikvm(12355): Link of class 'Lorg/apache/harmony/awt/datatransfer/NativeClipboard;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/media/session/MediaSessionCompatApi21$CallbackProxy; (231) W/dalvikvm(12355): Link of class 'Landroid/support/v4/media/session/MediaSessionCompatApi21$CallbackProxy;' failed W/dalvikvm(12355): Unable to resolve superclass of Landroid/support/v4/media/session/MediaSessionCompatApi23$CallbackProxy; (810) W/dalvikvm(12355): Link of class 'Landroid/support/v4/media/session/MediaSessionCompatApi23$CallbackProxy;' failed W/dalvikvm(12355): Link of class 'Lcom/zxinsight/share/activity/ShareWeiboActivity;' failed W/chromium(12355): [WARNING:proxy_service.cc(890)] PAC support disabled because there is no system implementation E/AndroidProtocolHandler(12355): Unable to open asset URL: file:///android_asset/mw_fingerprint.html 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览