Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio ERROR: Cannot resolve symbol 'View'

Tags:

I'm trying to follow this tutorial from Google to create your own android app with Android Studio. But when I follow the 4th step on this page: http://developer.android.com/training/basics/firstapp/starting-activity.html Android Studio ends up with this error:

Cannot resolve symbol 'View' 

This is what my code looks like at the moment:

public class MainActivity extends ActionBarActivity {     /** Called when the user clicks the Send button */     public void sendMessage(View view) { <--- (This line ends up with the error)         // Do something in response to button     }      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);     }       @Override     public boolean onCreateOptionsMenu(Menu menu) {         // Inflate the menu; this adds items to the action bar if it is present.         getMenuInflater().inflate(R.menu.menu_main, menu);         return true;     }      @Override     public boolean onOptionsItemSelected(MenuItem item) {         // Handle action bar item clicks here. The action bar will         // automatically handle clicks on the Home/Up button, so long         // as you specify a parent activity in AndroidManifest.xml.         int id = item.getItemId();          //noinspection SimplifiableIfStatement         if (id == R.id.action_settings) {             return true;         }          return super.onOptionsItemSelected(item);     } } 

What's wrong with this code? I'm not experienced in java and after looking at other questions I still couldn't find the right solution.

Thanks for helping!

like image 926
Stefan Avatar asked Jan 05 '15 12:01

Stefan


People also ask

What does Cannot resolve symbol mean?

“cannot resolve symbol” means that the Java compiler cannot locate a symbol referenced in your Java source code. The causes for this common error include: A missing class file. A faulty CLASSPATH.


2 Answers

I think you forget to include the import statement for View. Add the following import in your code

import android.view.View; 
like image 195
BeingMIAkashs Avatar answered Sep 25 '22 07:09

BeingMIAkashs


I am doing the same tutorial and ran into the same problem (that's why I found this question).

I see they explain this issue in the next paragraph named "Build an Intent":

Android Studio will display Cannot resolve symbol errors because this code references classes that are not imported. You can solve some of these with Android Studio's "import class" functionality by pressing Alt + Enter (or Option + Return on Mac). Your imports should end up as the following:

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText;

  • https://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent
like image 25
Vincent Avatar answered Sep 25 '22 07:09

Vincent