Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setContentView(R.layout.Main); Main cannot be resolved or is not a field

This is a simple program for beginning (simple for you, not for me) eclipse. I want to change a text by clicking on a button, but it's not working.

Here is the code:

package com.example.androidcourse;  

import android.app.Activity;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
import android.widget.TextView;  
import android.R.layout;  

public class MainActivity extends Activity {  

@Override 
public void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
setContentView(R.layout.Main);  


Button btn = (Button) findViewById(R.id.but_action); 
final TextView text = (TextView) findViewById(R.id.txt_caption);  
btn.setOnClickListener(new OnClickListener() {  

@Override  
public void onClick(View v) {
text.setText("New bingo...");  
}  
});  
}  
}  
like image 405
max Avatar asked Dec 05 '22 14:12

max


1 Answers

First just build your project. If it will not work, then delete from imports android.R.layout and use layout from your package.

like image 87
ania Avatar answered Feb 13 '23 13:02

ania