Rishabh Poddar
Rishabh Poddar

Reputation: 984

android xml error: 'class' or 'interface' required

I am new to android development. Here is my XML code for one of an activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.*****.*****.DisplayMessageActivity">
<TextView
    android:id="@+id/view_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>

As seen above, I want the TextView to have id view_text. But as soon as I write android:id="@+id/view_text", it gives an error saying 'class' or 'interface' expected.

There are no errors in any of the other files. As soon as I remove android:id="@+id/view_text", everything works perfectly fine.

Also I am using the latest version of android studio. Just this problem.

DisplayMessageActivity: public class DisplayMessageActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
    TextView textView = (TextView)findViewById(R.id.view_text);
    textView.setText(message);
    setContentView(R.layout.activity_display_message);
}

@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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

Please help. Thanks

Upvotes: 0

Views: 1568

Answers (1)

Ajay Sharma
Ajay Sharma

Reputation: 38

To reverse the effect of accidentally invoking Inject Language, place the caret inside the literal string where you injected the language (e.g. somewhere in @dimen/view_text in your first screenshot) and then invoke "show intention actions" (Alt-Enter, or Option-Enter on Mac). One of the last options in the menu should be "Un-inject Language ".

Upvotes: 1

Related Questions