赞
踩
记录我遇到的kotlin与android的问题
第一篇Android与kotlin报错
第三篇Android与kotlin报错3
图标和文字对不齐
连线,把文字的上端与图标的下端连接起来
Lint found fatal errors while assembling a release target.
修改build.gradle(:app) 里的targetSdkVersion版本号
lateinit property context has not been initialized
application没有注册就可能导致应用的方法无法调用
注册application
TabLayout无法调用setupWithViewPager方法
是TabLayout 不是TableLayout 这是两个控件,你用错了
将tablelayout改成tablayout
如果还不行,就导入以下这个包
implementation(“com.android.support:design:28.0.0”)
我的setupWithViewPager这个方法为什么会报红?谢谢
Type mismatch.
Required:
android.support.v4.view.ViewPager?
Found:
androidx.viewpager.widget.ViewPager
将整个项目升级到AndroidX。
升级Android Studio后,在 Refactor —> Migrate to AndroidX 路径下可以将整个项目升级到AndroidX。
android.support升级到androidx踩坑记录
A problem occurred evaluating settings ‘mydiary-main’.
Could not find method dependencyResolutionManagement() for arguments [settings_5ga1sxw4u2n9vtftquyztpke1$_run_closure1@c3b9a33] on settings ‘mydiary-main’ of type org.gradle.initialization.DefaultSettings.
在setting.gradle中
只留下
rootProject.name = “MyDiary”
include ‘:app’
在as中kotlin不能直接用id来获取xml组件
在build:gradle(Module)中 开头换成
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
Unparseable date: “”
date获取的值为空
调整获取值变量的位置,使其能够识别获取
善于用log和Toast去进行测试
关于获取EditText编辑框中的值为空的问题
cannot find implementation for com.example.test1.db.AppDataBase. AppDataBase_Impl does not exist
在依赖中添加
implementation "androidx.room:room-ktx:2.2.5"
kapt "androidx.room:room-compiler:2.2.5"
解决:cannot find implementation for XXX. XXX_Impl does not exist
用kotlin伴生对象生成全局context,运行时报错,lateinit property context has not been initialized
可能是manifest中没有注册该kt文件,继承Application的类也需要注册
You need to use a Theme.AppCompat theme (or descendant) with this activity.
将AndroidManifest.xml文件中关于Activity的主题配置改成
android:theme="@style/Theme.AppCompat.Light.NoActionBar
You need to use a Theme.AppCompat theme (or descendant) with this activity. 完美解决
Room cannot verify the data integrity. Looks like you’ve changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
将应用卸载,再运行就能解决
menu菜单无法显示
修改themes中的界面主题
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Android Menu菜单-菜单无法显示_Primer5-程序员秘密
recyclerview删除item的时候,报错, IndexOutOfBoundsException: Index: 1, Size: 1
数组越界导致
在RecyclerViewAdapter的类里重写了getItemCount()方法,更新数据集合时,长度有变化,试图也变化了,但是getItemCount()方法并没有并没有更新,导致getItemCount()返回的数据集合的长度值与当前的数据集合的长度值不一致,出现以上的错误。
解决这类问题的方法就是及时刷新RecyclerViewAdapter的数据
保证当前的数据集合与adapter的内部数据集合一致
以下有几个方法:
notifyItemRangeRemoved()
notifyItemRangeInserted()
notifyItemRangeChanged()
notifyDataSetChanged()
例子
view.show_note_dialog_del.setOnClickListener {
//todo 15:40 对照java版本,对照kotlin的删除数据库的方法
GlobalScope.launch(Dispatchers.Main) {
noteRepository.del(data.id)
notifyDataSetChanged()
mDataList.removeAt(position)
notifyItemRemoved(position)
}
dialog.dismiss()
}
RecyclerView 出现java.lang.IndexOutOfBoundsException: Index: 13, Size: 12 问题解决
An exception occurred applying plugin request [id: ‘com.android.application’]
Failed to apply plugin ‘com.android.internal.application’.
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changingorg.gradle.java.home
ingradle.properties
.
If the JVM points to version 1.8 then you should change it in settings. You can find it in Preferences → Build, Execution, Deployment → Build Tools → Gradle → *Gradle JDK.
Error message “Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8”
编写简单的播放网络资源的mediaplayer,代码没错,界面能进去,但是无法播放,在模拟器能播放,在真机无法播放
APP改用https请求
或多等一会
可能是无法http请求
或者是正在下载,等下载完毕后就能播放
(Android MediaPlayer无法在API 26+上播放音乐)[https://www.it1352.com/1908983.html]
(Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法)[https://blog.csdn.net/gengkui9897/article/details/82863966]
java.io.IOException: Prepare failed.: status=0x1
mediaPlayer.setDataSource("http://www.ytmp3.cn/down/57799.mp3")
mediaPlayer.prepareAsync()
mediaPlayer.setOnPreparedListener {
mediaPlayer.start()
}
或者用协程
GlobalScope.launch(Dispatchers.IO) {
}
GsonConverterFactory.create()找不到类
依赖添加
compile ‘com.squareup.retrofit2:converter-gson:2.0.2’
GsonConverterFactory.create()找不到类
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ‘:app:debugRuntimeClasspath’.
在as中选择file->setting->gradle->选择正确的gradle user home
例 C:\Users\moli.gradle\wrapper\dists
gradle出现编译问题Error:Could not resolve all dependencies for configuration ‘:app:debugRuntimeClasspath’.
Unresolved reference: liveData
添加依赖
implementation "android.arch.lifecycle:extensions:1.1.1"
Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Go to the documentation to learn how to Fix dependency resolution errors.
需要在gradle.properties中添加下面两行代码
这是因为混合支持库。通过添加这些行选择androidX作为您的支持库
android.useAndroidX=true
android.enableJetifier=true
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?
AndroidStudio无法自动连接模拟器,每次连接都用命令提示符连接
复制adb.exe所在的路径(AndroidSDK路径下的platform-tools目录内)
例:D:\Software\AndroidStudio\AndroidSDK\platform-tools
粘贴到环境变量里的path中
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test1/com.example.test1.MainActivity}: android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070091
将图片删了,然后复制粘贴到drawable,然后再重新装填图片
Inheritance from an interface with ‘@JvmDefault‘ members is only allowed with -Xjvm-default option
直接在kotlinOptions中添加如下内容
freeCompilerArgs += [
“-Xjvm-default=all”,
]
Inheritance from an interface with ‘@JvmDefault‘ members is only allowed with -Xjvm-default option
Caused by: java.lang.RuntimeException: cannot find implementation for com.example.datastorage.WordRoomDatabase. WordRoomDatabase_Impl does not exist
//主要就是这三个,你要看是否一致,使用是否正确,如果你使用了kotlin 三个缺一不可
implementation "android.arch.persistence.room:runtime:1.1.1"
//注意看 后缀还不一样 room:compiler
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
安装时提示app签名不一致,应用可能被修改
修改build.gradle文件中的applicationId
Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.7.0-runtime
在gradle.properties中添加下面两行代码
android.useAndroidX=true
android.enableJetifier=true
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?
导入依赖后,在activity或者fragment中无法使用依赖所包含的类
在setting.gradle中 添加jcenter()的库
打开相册时,选定相册的图片后会闪退(相当于finish())
在manifest的application标签下面添加一行
android:requestLegacyExternalStorage="true"
当针对Android 10时,WRITE_外部存储不再提供写入访问
EditText获取的值为空
没刷新ui
在ui刷新页面的方法里操作,例如在按钮的点击事件中进行操作
使用BottomNavigationView做底部导航,menu、MainActivity、activity_main、navigation 都设置完了,运行时只显示界面,点击下方的BottomNavigationView不能进行fragment的切换
navigation 与menu与appBarConfiguration内id不一致
navigation 与menu与appBarConfiguration内id必须一一对应并且一致
启动androidstudio提示 Failed to load JVM DLL if you already have a 64-bit JDK installed,define a JAVA_HOME variable in xxx
下载jdk 配置jdk环境变量
JAVA环境变量配置详解(全网最新详细教程)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.secondhandtest/com.example.secondhandtest.MainActivity}: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property binding has not been initialized
在fragment中使用findviewbyid() 而不是使用viewbinding
在fragment中使用findviewbyid()
https://github.com/1120026847/BottomNavigationView
获取不了bmob数据,bmob获取到的list集合为Goods@99ceb1,在recyclerview显示不出内容
实体类出现错误
出现这种原因,最好把要实现的地方分离出来,然后逐个排查
检查实体类继承的数据类型是否正确
bmob无法获取user字段的值,只能获取实体类的默认值
如果你已经有使用以下代码关联实体类和用户信息
val user:User=BmobUser.getCurrentUser(User::class.java)
你要确保bmob云数据库中的字段名和实体类的字段名一致
recyclerview显示位置有所偏差,显示偏下面
在activity_main.xml中用fragment引用navigation,navigation的startDestination是recyclerview的界面
androidx.constraintlayout.widget.ConstraintLayout的布局中fragment会自动偏下
这是布局,使用fragment标签引用navigation
navigation首个启动导航是navigation_explore,那个fragment就是显示recyclerview
在主布局activity_main.xml中 使用线性布局LinearLayout,并调整fragment的位置
Android使用支付宝沙盒报错,提示String的长度是空指针异常
Attempt to invoke virtual method ‘int java.lang.String.length()’
检查demo中的RSA2_PRIVATE与RSA_PRIVATE输入是否正确
RSA2_PRIVATE的值为
RSA_PRIVATE的值为
或者将RSA2_PRIVATE与RSA_PRIVATE数值对调
2.
在SignUtils中的sign的KeyFactory的参数中,删除第二个参数
支付宝沙盒点击支付时提示
I/msp: {resultStatus=4000, result=, memo=系统繁忙,请稍后再试}
1.没有安装支付宝沙盒app
2.代码要在主程序的oncreate下添加一行代码表示沙盒测试,才能启动支付宝沙盒app
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
2.检查公钥和私钥
3.没配置activity
【支付宝】支付宝支付失败:4000
支付宝 支付返回 4000 ,系统繁忙请稍后再试
支付宝支付返回错误码4000
支付宝沙盒支付提示 客户端报错“商户合作协议已到期,无法继续使用,请联系商户处理。(ALIN42274)
联系支付宝客服,提供自己的appid,让他们去重新挂载功能包
Android Studio3.5+中文字体不一致的问题
Android Studio升级3.5之后,会出现中文字体不一致的问题,原因是升级后,部分英文字体不包含中文字库,解决方法:
如果没有显示Current editor font:xxx–defined in the color scheme,则直接修改Editor->Font->Fallback font中的字体即可,比如SimHei。
如果显示了Current editor font:xxx–defined in the color scheme,则应该修改Editor->Color Scheme->Color Scheme Font->Fallback font中的字体,比如SimHei。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。