Learn how to resolve the 'RandomAccessFile' import issue on Android Studio.

How to resolve Android Studio Error: Cannot resolve symbol 'RandomAccessFile'

The Java RandomAccessFile class is used to access files in random way, this means it allows you to move around a file and read from it or write to it as you want. Thing that is not possible with the traditional FileInputStream or FileOutputStream classes.

If your code uses this class, the exception on the IDE "Cannot resolve symbol 'RandomAccessFile'" will appear due to the absence of importing the related class. This class can be imported in your class with the following line at the top of your class:

import java.io.RandomAccessFile;

Don't forget as well that Android Studio has an autoimport feature that recognizes classes if they're already in the android namespace. This dialog appears if you wait enough over the same line of code that throws the exception (the time differs of your device performance):

Android Studio Class Autocomplete (auto import)

Pressing Alt + Enter on the recommendation will auto import the java.io.RandomAccessFile namespace at the beginning of your Java code.

Happy coding !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors