If you are new to Android development, especially using Android Studio, you will encounter a lot of issues and error displays. Some errors are easy to figure out, while others seem to be discouraging. More so, with these errors, you’ll learn a lot — it’s part of the process. So, in this article, we tackle one common problem, newbie Android developers have —
Cannot resolve system 'textView'.
Learning the theory and the concepts in Android app development without applying seems to be futile. On the flip slide, if you start to do programming by just simply copying codes available on the internet, chances are, you’ll encounter errors difficult to explain. Copying codes is a good start, but you must also learn the concepts of why these lines of codes are grouped and worked or didn’t work as expected.
Android Studio and the
Android Studio is a user-friendly Android app development you can install on your computer. It’s packed with everything you need to kick start your Android app development journey. All you need to do is download and install Android Studio and you’re set to go.
It has a code editor interface that lets you write code using Java, C++, and more — just get the extension for the programming language you will use. Likewise, you can simply copy codes available only to see how marvelous Android Studio is. One of the useful controls that you can maximize in Android Studio is the
TextView. It’ll display the output on a non-editable interface based on the user’s requirements. There are two ways to create the TextView control — XML layout file and in the Activity file.
First, you need to make the activity_main.xml, where you can define the code for
TextView. XML is used in Android Studio for designing the layout because it’s lightweight. You can define everything about your layout here, depending on your requirements. Once you are done; you now need to call it from your MainActivity.java. Details on the codes are out of the scope of this article.
Cannot Resolve System 'textView'
Some neophyte Android developers who encountered this problem reported that they have copied sample codes from the internet, in a verbatim manner. Even though you copied the codes, there are three reasons why you can encounter the error. This error isn’t explicitly displayed. What you can see, however, are the
TextView turning red. Hovering on it with your mouse pointer, the error will be displayed.
Missing Import Statement/Library
Since you created the
TextView separately, you’ll definitely bump into this error if you don’t import the
TextView class. If you don’t use auto-complete, when typing out the class name, you need to import it manually.
Missing/Incorrect TextView Object
You must check the XML and your main project. The object of your
TextView in the main activity must be consistent with the
android:id in your XML file. Incorrect argument could make
TextView class red, which, when hovered, you’ll read error:
Cannot Resolve System ‘TextView.’
Quick and Easy Way to Make this Error Go Away
Errors and roadblocks are inevitable for Android developers. And, so long as you won’t give up, every issue has solutions. And, for this issue, there are three things that you can try.
Whether you have encountered the problem or not, the wise thing to do when coding on Android Studio is to use the autocomplete. The good thing about autocomplete is that, when you type the class name, Android Studio will auto-import it for you. This means you don’t need to manually import the class – which is prone to error. You can try this by going to File>Settings>Editor>General>Auto Import.
You can tick all the options or you want to be asked every time you write or paste a class name in your java source. When this option is enabled, the class along with its package will be imported when you call out that particular class.
Likewise, you can just hover over
TextView and press ALT+ENTER to import the class. You can do manual tagging of the
TextView with the following:
import android.widget. TextView;
Rebuild the Program
This problem is actually very basic and a quick restart of the Android Studio does the trick for most. But this isn’t just any ordinary restart. Go to File>Invalidate Caches/Restart…, then a popup window will be displayed. Click the Invalidate and Restart button. Your Android Studio will exit and restart automatically. The process will take a while before it is completed. Once it is done, check that the error disappears.
Check TextView Object
When the first and second solutions won’t work, then, there is something wrong with your code. Try checking your XML file again. Then, look for the
android:id=textView or, whichever you declared. When calling it from your main activity, the ID should be consistent.
The Final Say
Cannot Resolve System 'textView' is an error you get on Android Studio if you have problems with the TextView class. Whether you haven’t imported
TextView class or there are inconsistencies with the
TextView ID. For the former, you can restart the Android Studio and the error should be fixed. If not, try checking if TextView class is imported successfully. Autocomplete import of class is also a great way to do away with this error.
Finally, check whether the
TextView ID is consistent with your XML layout file and your main project. With intelligent troubleshooting and the solutions we recommend above, you can continue coding without a problem.
I am a Software developer with approx 4 years of experience in building various responsive and beautiful websites and apps.
Language: Ruby, Java, HTML/CSS, Android
Frameworks: Ruby on Rails, Hosting: Heroku, Godaddy
Database: Mysql, Postgres, Mongo, Oracle
Also please look on my stack overflow profile.