简体   繁体   English

如何解决 Android Studios 中的“readLines”错误

[英]How to resolve 'readLines' error in Android Studios

I'm currently building an app with Java on Android Studios but I ran into a problem.我目前正在 Android Studios 上使用 Java 构建应用程序,但我遇到了问题。

items = new ArrayList<>(FileUtils.readLines(getDataFile(), Charset.defaultCharset()));

I get an error from this line saying 'cannot resolve method readLines'我从这一行收到一条错误消息,说“无法解析方法 readLines”

My dependencies in my build.gradle are as followed我的build.gradle中的依赖如下

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'commons-io:commons-io:2.6' //First tried this one
    implementation 'org.apache.commons:commons-io:1.3.2' //Then tried this one
}

The bottom two lines are what I tried to use to solve the issue but I still get the error.下面两行是我试图用来解决问题的,但我仍然收到错误。

I also have import android.os.FileUtils;我也有import android.os.FileUtils; in my java class but still nothing.在我的 java class 但仍然没有。 Please help!请帮忙!

Use利用

import org.apache.commons.io.FileUtils;

Worked for me.为我工作。

Try implementation 'commons-io:commons-io:2.11.0' from https://commons.apache.org/proper/commons-io/dependency-info.html .尝试从https://commons.apache.org/proper/commons-io/dependency-info.html implementation 'commons-io:commons-io:2.11.0' Then import it in your project like this import org.apache.commons.io.FileUtils;然后像这样导入它到你的项目中import org.apache.commons.io.FileUtils; . . Make sure you're not importing android.os.FileUtils already.确保您没有导入android.os.FileUtils

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM