Question

[Solved] Android Studio ERROR: Cannot resolve symbol ‘View’

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);
    }
}

Whats wrong in this code? I’m not experienced in java and after looking at other questions I still couldnt find the right solution.

Thanks for helping!

Enquirer: Stefan

||

Solution #1:

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

import android.view.View;
Respondent: BeingMIAkashs

Solution #2:

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

Respondent: Vincent

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy