赞
踩
记录下我遇到kotlin的错误与解决方法,希望对你有所帮助
记录我遇到的kotlin与android的问题
第二篇Android与kotlin报错2
第三篇Android与kotlin报错3
Kotlin: Cannot access java.io.Serializable’ which is a supertype of ‘kotlin.Int’. Check your module classpath for missing or conflicting dependencies
I got the same error today after Intellij upgraded my bundled kotlin plugin on Mac OS. The problem might not be the same, but the error message was identical.
Turns out before my project was using JDK 11, but after the kotlin plugin upgrade the JDK was upgraded as well to 13. I resolved the issue by dropping the existing JDK 11 with the - button in the Project Structure window and then adding it again using the + button - which selected JDK 13 by default. After that this error went away.
将项目结构中sdk旧版全删除,只保留14
如果提示项目没有sdk,再按照提示下载即可
https://discuss.kotlinlang.org/t/cannot-access-java-io-serializable-which-is-a-supertype-of/16595/3
Error:(9, 1) Kotlin: Conflicting overloads: public fun largerNumber(num1: Int, num2: Int): Int defined in root package in file three.kt, public fun largerNumber(num1: Int, num2: Int): Int defined in root package in file two.kt
Error:(6, 15) Kotlin: Overload resolution ambiguity:
public fun largerNumber(num1: Int, num2: Int): Int defined in root package in file three.kt
public fun largerNumber(num1: Int, num2: Int): Int defined in root package in file two.kt
Error:(3, 1) Kotlin: Conflicting overloads: public fun largerNumber(num1: Int, num2: Int): Int defined in root package in file three.kt, public fun largerNumber(num1: Int, num2: Int): Int defined in root package in file two.kt
D:\IDEA\20200524-1\src\two.kt
D:\IDEA\20200524-1\src\three.kt
不同文件中不能定义相同名称的函数,否则报错
注释掉相同名称的函数
Overload resolution ambiguity. All these functions match
变量的引用模糊不清
重新定义变量名
Unresolved reference: name5
只要设置权限修饰符在要调用的类就能解决
An operation is not implemented: Not yet implemented
没有重写方法
将重写的方法生成的todo删除即可,如下
TODO("Not yet implemented")
todo标识符如果没解决,会有运行时异常
Too many arguments for public constructor Cellphone( defined in数据类与单例类. Cellphone
构造器Cellphone名称 太多而引发的冲突
将多个Cellphone改名
Error running ‘app’: Default Activity not found
找不到主程序来进行启动
注意activity标签的前缀和后缀是否在合适的位置
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
已经有布局,但是无法识别,提示Unresolved reference: right. fragment
复制布局的代码,删除已有布局,用万能键创建布局,粘贴进去,就能识别
Unresolved reference: from
注意区别标红语句的那一段每个字母的大小写,如果看不出来可以复制别人的相同代码然后粘贴就能识别
Failed to install the following Android SDK packages as some licences have no been accepted
在下方build,在最下方提示install xxxxxx ,点击安装即可
Caused by: java. lang. ClassCastException: android. widget . FrameLayout cannot be cast to com. example . a20200616study . NewsContentFragment
at com.example . a20200616study . NewsContentActivity . onCreate (NewsContentActivity.kt:28)
有多个相同名称的变量,要注意导包,别导错了
若不会用debug,要善于用ait+变量名与ctrl+f来进行查代码
java报错 Cannot resolve symbol ‘java’ Unused import statement
java报错 Cannot resolve symbol ‘java’ Unused import statement
ERROR: Gradle version 2.2 is required. Current version is 6.2-rc-3.
报错:ERROR: Gradle version 2.2 is required. Current version is 6.2-rc-3.
‘androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner’ for AndroidJUnit4 could not be loade
将import androidx.test.ext.junit.runners.AndroidJUnit4;替换成import androidx.test.runner.AndroidJUnit4;
找不到或无法加载主类
android.view.InflateException: Binary XML file line #2 in com.example.materialcardview:layout/fruit_item: Binary XML file line #2 in com.example.materialcardview:layout/fruit_item: Error inflating class com.google.android.material.card.MaterialCardView
布局无法解析当前组件,同时调用不了对象的方法
如果布局无法解析,对象调用不了相应的方法,而没有拼写错误,就是没有添加依赖
添加相应的依赖即可
Invoke-customs are only supported starting with Android O (–min-api 26)
build.gradle(:app)中的minSdkVersion设置为26即可
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void androidx.appcompat.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)’ on a null object reference
添加setSupportActionBar(toolbar);
在getSupportActionBar().setDisplayHomeAsUpEnabled(true);之前
ERROR: Failed to resolve: org.junit.jupiter:junit-jupiter:
Affected Modules: app
在build.gradle(:app)中的dependencies闭包中删除关于jupiter的引用
例: implementation ‘org.junit.jupiter:junit-jupiter’
Cannot resolve symbol ‘DBOpenHelper1’
如果确定有这个变量或者类,那就在类或者变量名复制粘贴,让AS重新识别,或者删掉,手动重新输,看AS会不会给提示
错误: 找不到符号
setContentView(R.layout.activity.login);
^
符号: 变量 activity
重启AndroidStudio
引用 AndroidStudio 3.6 中 R.layout 找不到对应的xml文件
布局加载空白
重载另一个常用的OnCreate(@Nullable Bundle savedInstanceState)方法
引用
关于onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState)的问题
java报错 Cannot resolve symbol ‘java’ Unused import statement
idea 卸载重新下载时候,配置发生错误,无法识别sdk
在下拉选项中换一个即可
错误:无效的源发行版:11
将 project language level 中选择sdk default 即可,如图所示
https://blog.csdn.net/qq496013218/article/details/56845485
报错:ERROR: Gradle version 2.2 is required. Current version is 6.2-rc-3.
改build gradle(第一个),依赖的 classpath,新建项目然后复制替换进去即可
在buildscript和allprojects的repositories下添加google(),然后同步即可
看到编码和目录就想到as不支持中文,把项目复制粘贴到一个新的英文文件夹,然后导入即可
在app module的build gradle 中 在依赖中,将com.android.support:appcompat-v7:26.2.1改成 com.android.support:appcompat-v7:26+’
net start mysql 发生系统错误2 系统找不到指定的文件
原文出处:https://www.jianshu.com/p/6d8ed7c36e6f
原文出处:https://www.cnblogs.com/caiyishuai/p/10783198.html
Could not resolve all files for configuration ‘:app:debugCompileClasspath’
原文如下:https://blog.csdn.net/wjj1996825/article/details/80900875
https://www.jianshu.com/p/9de30197b528
JUnit Test 测试 initializationError错误
Spring框架与JUnit版本不兼容,我的Spring4.3.18,JUnit4.12,将JUnit降至4.4左右版本即可。
引用:https://www.cnblogs.com/umeall/p/9236233.html
‘androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner’ for AndroidJUnit4 could not be loade
将import androidx.test.ext.junit.runners.AndroidJUnit4;替换成import androidx.test.runner.AndroidJUnit4;
关于使用dataBinding时无法自动生成binding类的问题
重启as。。
在xml中找不到viewmodel的get方法
viewmodel中get方法中的get后面第一个字母要大写
Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;30.0.2 Android SDK Build-Tools 30.0.2
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: C:\Users\Administrator\AppData\Local\Android\Sdk
License for package Android SDK Build-Tools 29.0.2not accepted
����: ���� lose_score_message
�: �� string
报错乱码
Android Studio 4.1 Build状态栏输出出现中文乱码的问题
设置完,关闭as,再重启
注意String.xml中关于变量的name的拼写
错误: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
public class Word {
^
Tried the following constructors but they failed to match:
可以构建一个空的构造函数 public Word(){}
Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle
Error:Connection timed out: connect
Cause: android-apt plugin is incompatible with the Android Gradle plugin. Please use ‘annotationProcessor’ configuration instead.
Error:android-apt plugin is incompatible with the Android Gradle plugin. Please use 'annotationProce
Cannot resolve constructor ‘ViewModelProvider
(com.example.myapplication.WinFragment,androidx.lifecycle.ViewModelProvider.NewInstanceFactory)’
如果出现找不到构造器的提示,就删除就删除import导包,重新导一遍
错误: 找不到符号
import com.example.viewmodelsavedstate.databinding.ActivityMainBindingImpl;
^
符号: 类 ActivityMainBindingImpl
位置: 程序包 com.example.viewmodelsavedstate.databinding
在XML界面文件上出错了,重点检查databinding的界面语法,比如<variable>
, @{ }中的内容。
错误: 找不到符号 符号: 类 ActivityMainBindingImpl 位置: 程序包 com.example.databinding.databinding
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ‘:classpath’.
Android Studio 报 Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfig 的错误
A problem occurred configuring root project ‘test2’.
Could not resolve all artifacts for configuration ‘:classpath’.
Could not find com.android.tools.build:gradle:6.9.1.、
更改build.gradle(app) buildscript下的dependencies下的classpath的gradle的版本号
在idea运行不了 android程序可以尝试
换build.gradle(:app)的 classpath "com.android.tools.build:gradle:3.5.0"里面的gradle:xxx
在https://services.gradle.org/distributions/中下载gradle,然后存放在 C:\Users\JF628.gradle\wrapper\dists 目录下,在gradle-wrapper.properties中更换distributionUrl=https://services.gradle.org/distributions/gradle-7.2-all.zip
AVD XXX is already running. If that is not the case, delete the files at xxx*.lock and try again
AVD XXX is already running. If that is not the case, delete the files at xxx*.lock and try again解决方法
Unable to create Debug Bridge: Unable to start adb server: error: protocol fault (couldn’t read status): Connection reset by peer
‘D:\it\Android\sdk\platform-tools\adb.exe start-server’ failed – run manually if necessary
Unable to create Debug Bridge:Unable to start adb server
结束5037号端口号的占用,然后重启AS
Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
取消安装API Level 31 安装API Level 30
取消安装31.0.0,安装30.0.3
出处
2021-07-19 Android studio:Installed build tools revision 31.0.0 is corrupted.Remove and install ag
Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for android:exported
when the corresponding component has an intent filter defined.
出处
Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit
Execution failed for task ‘:app:packageRelease’.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
com.android.ide.common.signing.KeytoolException: Failed to read key key0 from store “D:\it\Android\key\key.jks”: Get Key failed: getSecretKey failed: Password is not ASCII
百度翻译了一下,发现key密码设置的不合法。重新新建一个key,密码设置字母和数字混搭,解决。
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class kotlinx.coroutines.AbstractCoroutine found in modules jetified-kotlinx-coroutines-core-1.3.0.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0) and jetified-kotlinx-coroutines-core-jvm-1.4.3.jar (org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.3)
将implementation "androidx.paging:paging-runtime-ktx:3.0.1"换成implementation ‘androidx.paging:paging-runtime-ktx:2.1.1’
在everything中搜索冲突jar包的关键词(coroutines),然后把冲突的jar包删除,再去build.gradle(:app)中的dependencies闭包中,一个一个删除所对应的依赖(删除前记得备份),然后删除再rebuild Project,看看冲突的jar包在哪一个依赖中生成,就将该依赖降低版本(可在https://developer.android.google.cn/中查询)
依赖能用就行,别升最高,最高有可能都是bug
你的主机中的软件中止了一个已建立的连接。
1.如果开发中不需要电脑的 Wi-Fi 热点,关闭热点就可以了;
2.如果需要热点,那么将 Gradle 回退到 6.5 之前的版本,注意,Android 的 Gradle 插件 版本也要同步回退。
来源:
Android Studio:你的主机中的软件中止了一个已建立的连接。
The following classes could not be found:
- androidx.fragment.app.FragmentContainerView
在应用或模块的 build.gradle 文件中添加所需工件的依赖项:
implementation “androidx.fragment:fragment:1.3.6”
来源
FragmentContainerView not found
在kotlin无法用id来引用xml的组件
使用View Binding
viewBinding{
enabled=true
}
package com.example.gitdemo
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.gitdemo.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding:ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding= ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.textView.text="helloworld"
}
}
Timed out after 300seconds waiting for emulator to come online.
Although there could be various reasons for this behaviour… Mostly it may be due to error in system images or the API version you are using
better you download latest system images and make sure the compatibilty of API version you are using.
enter image description here
If problem exists
I would like to suggest some fixes: Try them
1)Uninstall/Reinstall Android SDK to folder.
OR
OR
3)create a new Virtual Device.
OR
4)set “Max VM application heap size” hardware property to 192 or higher and pick the QVGA skin.
hope it helps.
卸载adb,重装其他型号的adb
Error while waiting for device: Timed out after 300seconds waiting for emulator to come online
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘com.android.internal.application’]
将项目的路径改为纯英文
Android Studio出现Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to app
评论区
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper ‘jvm-target’ option
在build.gradle(:app) , android闭包下,输入
kotlinOptions{ jvmTarget=1.8 }
Unresolved reference: findNavController
依赖添加错误,添加以下依赖
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2' implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
一般来说,方法找不到,就是依赖引用错误
Could not initialize class org.codehaus.groovy.classgen.Verifier
在Settings->Build,Execution,Deployment->Build Tools->Gradle 选择Gradle user home的路径
Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
错误原因:gradle版本太低
修改gradle-wrapper.properties文件 , 使用6.3版本的Gradle
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip
类org.codehaus.groovy.vmplugin.v7.Java7找不到
Minimum supported Gradle version is 6.7.1. Current version is 5.6.4.
在https://services.gradle.org/distributions/中下载6.7.1以上的gradle文件,放在 C:\Users\JF628.gradle\wrapper\dists 目录下,然后到gradle-wrapper.properties中更改distributionUrl路径,与下载的gradle名称一样
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.drawerdemo/com.example.drawerdemo.MainActivity}: java.lang.IllegalStateException: Activity com.example.drawerdemo.MainActivity@f167fcb does not have a NavController set on 2131230883
private fun initNavigation() {
//获取Navigation的导航控制器 NavController
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
//把BottomNavigationView与NavController绑定。
binding.bottomNavView.setupWithNavController(navController)
}
Navigation Activity xxxxxx does not have a NavController set on 2131230958
Avd是灰色的,显示No Devices
点击Add Configuration , 点击加号add new Configurations 选择Android app,选择Moudule 和Before launch
viewbinding引用不了xml中include的引用的另一个xml文件的组件
先在include中设置一个id
<include
layout="@layout/content_layout"
android:id="@+id/include_head"
/>
然后在activity中引用
binding.includeHead.toolbar
Android ViewBinding更新,include得到优化
Gradle project sync failed. Please fix your project and try again.
编辑gradle-wrapper.properties文件,把路径写成正确的,有一个反斜杠要去掉。
Gradle project sync failed的解决方法
在a布局中include进去b布局,显示一片空白,显示不了b布局的组件
b本身的布局的组件高度和宽度显示的位置超出include的(a布局)显示范围,所以显示不了
删除marginTop属性调整一下距离顶端的位置
或者调整a布局的高度和宽度。使其能够容纳下b布局
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。