Cannot resolve symbol 'IOUtils'
Asked Answered
G

5

40

I have used the following code to create a temporary file in my android app:

public File streamToFile (InputStream in) throws IOException {
    File tempFile = File.createTempFile("sample", ".tmp");
    tempFile.deleteOnExit();
    FileOutputStream out = new FileOutputStream(tempFile);
    IOUtils.copy(in, out);
    return tempFile;
}

Now the problem is Cannot resolve symbol 'IOUtils'. I did a little bit of googling and discovered that for using IOUtils I need to download and include a jar file. I downloaded the jar file from here(commons-io-2.4-bin.zip). I added the jar named commons-io-2.4.jar from the zip to my bundle and when I tried to import it using:

import org.apache.commons.io.IOUtils;

It is showing error Cannot resolve symbol 'io'. So I tried to import it like:

import org.apache.commons.*

But still I am getting the error Cannot resolve symbol 'IOUtils'.

Question 1 : Why am I getting this error? How to resolve it?

Question 2 : Is there any way to create a temp file from an InputStream without using an external library? Or is this the most efficient way to do that? I am using android studio.

Graphite answered 4/7, 2014 at 16:33 Comment(1)
How to add Gson dependency to your Android appToratorah
G
9

Right clicking on the commons-io-2.4.jar file in project navigator and clicking 'Add to project' solved the issue.

Graphite answered 4/7, 2014 at 17:22 Comment(1)
@Zindarod late answer I know but see #17896057 for obtaining jarMusculature
O
102

For Android Studio:

  1. File -> Project Structure... -> Dependencies
  2. Click '+' in the upper right corner and select "Library dependency"
  3. In the search field type: "org.apache.commons.io" and click Search
  4. Select "org.apache.directory.studio:org.apache.commons.io:<X.X>

Or

Add implementation 'org.apache.directory.studio:org.apache.commons.io:2.4 to the build.gradle file

Octal answered 22/5, 2015 at 11:5 Comment(3)
Or add compile 'org.apache.directory.studio:org.apache.commons.io:2.4' to the build.gradle fileCarpeting
To see the Dependices tab, first click on "app" under "Modules".Calcimine
sometimes android studio doesn't install the dependencies if we do as in the answer. its better to do it manually like @JoaquinIurchuk saidShalondashalt
G
9

Right clicking on the commons-io-2.4.jar file in project navigator and clicking 'Add to project' solved the issue.

Graphite answered 4/7, 2014 at 17:22 Comment(1)
@Zindarod late answer I know but see #17896057 for obtaining jarMusculature
U
5

Adding below dependency solved issue

 implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
Unmixed answered 27/1, 2021 at 12:37 Comment(0)
D
3

For those who encountered this while working on a Netbeans Java project. What I did is I downloaded the Binaries Zip of IO here

Commons IO Util Jar Download Here

Then Right clicked on my Project>Properties>


On the Categories Pane, Click Libraries


Then Click Add Jar/Folder


Locate the jar file/folder of the extracted IO Util that was downloaded.


Then click Ok. That fixed mine. :)

Diannediannne answered 3/11, 2017 at 13:53 Comment(2)
The question is tagged with android-studio an answer about Netbeans doesn't answer it.Mandragora
android uses close to java syntax anyway.& I was searching for this exact problem that I encountered while working in netbeans that used to be an IDE for developing in android,seems to be worth pointing out. The Step by step problems and necessary jar files provided above for android-studio is close to what will solve the same problem above if encountered in Netbeans. I'm just providing my version of it in netbeans since this could be encountered while working in netbeans too. Fact is, I am working on this java proj.in netbeans so that I could deploy it in android later with working code.Diannediannne
H
0

First I added this dependency but got an error when installing the app on the device:

implementation("org.apache.directory.studio:org.apache.commons.io:2.4")

Error:

The application could not be installed: INSTALL_FAILED_NO_MATCHING_ABIS

Then based on the answers here, I used this other dependency in my build.gradle.kts file and it worked:

implementation("commons-io:commons-io:2.5")
Hereabout answered 18/11, 2023 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.