Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Kevin Carroll
Kevin Carroll
3,432 Points

Self-Destruct App - FileHelper.java - IOUtils (cannot resolve symbol)

I am getting an error in FileHelper.java when I add it to my project - IOUtils cannot be resolved. I saw a couple other posts about this, but people seem to be able to restart their computer or IDE and then it suddenly works. No such luck for me.

Details: I am using Android Studios and the commons-io-2.4.jar file is in my library. I have cleaned and rebuilt the project, as well as restarted Android Studio and my computer. The error is still there.

Kevin Carroll
Kevin Carroll
3,432 Points

Even though it was still showing an error for me, I ran the app anyway and it seems to run fine. The error that is being shown might just be an IDE bug.

2 Answers

I can confirm that Android Studio (and IntelliJ, which it's based on) do have issues with picking up changes to the build.gradle file. I often open the Gradle "tab" on the right side of the outer window frame, then press the "sync" button (not sure what these are called formally). My belief is that for performance, IJ parses and caches the content of build.gradle (Gradle likes to do this as well, but I think the problem here is IJ), and isn't being as good as it should be about watching for changes that might invalidate what it has cached.

Hey!

Not sure if it'll help in your case, but try right-clicking on the .jar in your lib folder, and click "Add As Library" from the menu. This will automatically format the build.gradle file so it will include your library, and perhaps get rid of said problem!

Also be sure to check what package each .java file is pointing to. Mine defaulted as com.treehouse.ribbit, though my package name was com.example.kevin.ribbit -- changing it fixed some errors.

Kevin Carroll
Kevin Carroll
3,432 Points

Thanks, that seems to have done the trick, with one small note:

I already had 'compile fileTree('src/main/libs') in my build.gradle file and right-clicking on the jar file to add as a library erased that line and added compile files('libs/commons-io-2.4.jar'), which caused a bunch of errors (there were other libraries I was using). I added back in compile fileTree('src/main/libs') along with compile files('libs/commons-io-2.4.jar') and that seems to have fixed the it.

Kevin Carroll
Kevin Carroll
3,432 Points

Actually, it looks like simply updating build.gradle at all (which causes it to resync) fixes the problem. It's possible that simply going to Tools->Android->Sync Project With Gradle Files could fix this as well.

Perhaps a rebuild alone would have fixed it. :) Glad it's workin' for ya, though!

Thank you Kevin!