Search code examples
androidandroid-widgetjavadoc

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

Solution

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