5

I defined TextView like : TextView newTextView;

then compiling the line:

newTextView = (TextView) findViewById(R.id.textView);

Android-studio gives error > cannot find symbol variable newTextView? At the same time Studio is acting weird like this variable name won't go into the blue color, there is "j" icon by the class names in the project structure and similar. Anybody know what happened to my project?

Nikanor
  • 262
  • 1
  • 5
  • 17
  • 1
    can you post the exact copy of the code you have in your file. – Sharjeel Sep 20 '15 at 21:19
  • Providing pieces of code is not helpful. Please post the whole portion of the relevant code. In addition to that, please post the full stacktrace of the error you're getting. – Nir Alfasi Sep 20 '15 at 21:24
  • Actually, I got lost project structure after restarting Studio, it's starting to behave very badly, doesnt recognize variables and classes. By the class names I have "j" icons.. It's actually not code that's the problem. something is happening with my project and I don't know what – Nikanor Sep 20 '15 at 21:27
  • @Nikanor if your project got messed up, create a new project, copy your code there and try again. – Nir Alfasi Sep 20 '15 at 21:28
  • I did that and I got the same thing..cannot rebuild the project because of same errors, I cannot find the the problem, it gives me "j" icons by the class names in the project structure (it's like doesnt recognize classes) – Nikanor Sep 20 '15 at 21:32
  • Can you post a screenshot of your project folder structure and your `app/build.gradle`? – tachyonflux Sep 20 '15 at 21:50

6 Answers6

6

It's working on my code that I've tested it...

Just make sure that you've imported this :

import android.widget.TextView;

And then make a Clean project.

EDIT

It's a problem of your SDK so better solution is update it.

Community
  • 1
  • 1
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
  • Would you expect to get "cannot find symbol variable newTextView" as a compilation error for a missing semicolon? – Nir Alfasi Sep 20 '15 at 21:25
  • Thanks, but that's not problem, everything is ok about that.. it's just my project is somehow behaving bad – Nikanor Sep 20 '15 at 21:25
  • A missing import is not the source of the problem as well. – Nir Alfasi Sep 20 '15 at 21:28
  • It's not code that's the problem. When I define TextView newTextView11; the variable does not become blue. – Nikanor Sep 20 '15 at 21:28
  • when try to build it says > package R does not exists, cannot find symbol variable textview again.. – Nikanor Sep 20 '15 at 21:31
  • That's what i tried it gives me same errors.. I will try to copy file by file – Nikanor Sep 20 '15 at 21:33
  • https://www.jetbrains.com/idea/help/symbols.html: Java class located out of the source root. – tachyonflux Sep 20 '15 at 21:39
  • It's something wrong with Android Studio itself. The same thing with new projects. I think incompatible SDK version or something like this can be a problem. How should I check this? – Nikanor Sep 20 '15 at 21:52
  • Yes, i did complete uninstall of Android Studio, and then reinstall with the latest version of API, then copied old project files inside a new project, synced, and everything is ok. But i had to do a completely removal of Android Studio. It was problem something regarding API incompatibility, i am still not sure. – Nikanor Sep 21 '15 at 19:16
  • So you can mark this question as a solved, I'll put what I said to you on my answer and by the way remove all of those comments to avoid chat. – Skizo-ozᴉʞS ツ Sep 21 '15 at 19:17
  • Thank you Sir ! Is it ok to call you Sir ? – Nikanor Sep 21 '15 at 19:22
  • That's a mystery ;)... (Remove all of your comments) – Skizo-ozᴉʞS ツ Sep 21 '15 at 19:23
4

If you're following the Google Android tutorial, when you create the second layout activity, and you pick a TextView widget, the ID of this widget it's "textView2".

You can:

Modify the findViewById() method and select the "textView2" view.

Or rename de ID of the view to "textView".

Angel Luis
  • 322
  • 4
  • 14
0

Make sure you selected the right widget. For me one issue is that in activity_display_message.xml I originally inserted a Text/Plain Text instead of a Text/Textview widget.

Autocomplete R.id then helped me to select the proper id of the textview, and of the editText in MainActivity

EditText editText = (EditText) findViewById(R.id.editText4); 
Johan
  • 1
0

What you can do is go to design view (in the activity) and select the TextView and make the ID for it as 'TextView'.It worked for me!!

Ravi Arora
  • 76
  • 6
-1

I used to magic of autocomplete to find that this is the correct attribute: -

R.id.textView2

I'm working through the tutorial myself, somewhat confusing I know.

Jason
  • 373
  • 1
  • 5
  • 14
  • `cannot find symbol variable newTextView` Sorry, I can't see how your post is related to this two years old problem. Please focus on relevant answers to recent questions. – Eugen Pechanec Oct 21 '17 at 17:55
-1

Used autocomplete to correct this. The variable name in my case was textView3

jimmy
  • 1
  • 1