Android Studio报错:Write access is allowed from event dispatch thread only

本文解决了在使用AndroidStudio编译工程时遇到的Writeaccessisallowedfromeventdispatchthreadonly错误。通过更换为AndroidStudio自带的JRE版本,避免了与本地安装的JDK版本冲突的问题。

新安装的android studio 编译工程时出现了Write access is allowed from event dispatch thread only 的错误。
在stackoverflow中发现答案:
So the problem was concluded in that android studio conflicted with my installed jdk version, so it was resolved when i checked jdk location (Project Structure -> SDK Location), ticked ‘Use embedded JDK’ checkbox and set jdk location to ‘path to android studio’\Android Studio\jre

意思就是:
给当前的android studio的jdk换个版本,使用android studio 自带的jre,因为自己电脑安装的jdk版本(以前安装过)和android studio sdk版本冲突。而且如果电脑没有安装过JDK,那么同理也一样使用android studio 自带的jre。

提供的参考引用中未提及解决 Android Studio 报错 `Attribute android:icon is not allowed here` 的方法。不过,通常这类报错可能是由于 XML 文件中标签属性使用错误、版本不兼容或者合并冲突等原因导致。以下是一些可能的解决思路: ### 检查 XML 文件语法 确保在 AndroidManifest.xml 或者其他 XML 布局文件中,`android:icon` 属性是在正确的标签下使用。一般 `android:icon` 属性应该在 `<application>` 或者 `<activity>` 等标签中使用。例如: ```xml <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"> ... </application> ``` ### 检查版本兼容性 确认 AndroidManifest.xml 中的 SDK 版本和 build.gradle 中的版本一致,避免版本不兼容导致的属性使用错误。比如确保 `android:targetSdkVersion`、`compileSdkVersion` 等版本一致: ```groovy android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.myapp" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } ... } ``` ### 清理和重建项目 有时候,项目的缓存文件可能会导致一些奇怪的报错。可以尝试清理项目缓存并重新构建项目: - 在 Android Studio 中,选择 `Build` -> `Clean Project`。 - 然后选择 `Build` -> `Rebuild Project`。 ### 检查合并冲突 如果项目中有多个库或者模块,可能会存在清单文件合并冲突。可以通过在 AndroidManifest.xml 中添加 `tools` 命名空间和 `tools:replace` 属性来解决合并冲突: ```xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.myapp"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" tools:replace="android:icon" ...> ... </application> </manifest> ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值