Wednesday, February 12, 2014

Novice: setContentView (R.layout.activity_main); issues


            
Today, setting up the android development environment, to make a hello world program
eclipse generated code actually wrong:
MainActivity.java
 
package com.jingtai.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater () inflate (R.menu.activity_main, menu);.
return true;
}
}



Say: setContentView (R.layout.activity_main); in this line
R cannot be resolved to a varialbel

Would not understand, how will eclipse the generated skeleton code wrong? Ah really hurt people
Reply:
R file because it is not generated, R is the file may not be introduced.
You can clean about your project. The menu bar point project, then clean.
If that does not work is the environmental problem. You use the latest api17 it? Make sure adt is 22., And the need to rise to android-SDK build tools latest version 17.
Reply:
clean under the project to try
Or you do not have to compile cause R does not generate
Reply:
clean look, if you still have problems in other parts of the project may be wrong, resulting in not automatically generate R.java
Reply:
Re-creating a new project, look good is not good, or if not, is to build environmental problems.
Reply:
cited a floor wlcw16 reply:
R file because it does not generate, it may not introduce R file.
You can clean about your project. The menu bar point project, then clean.
If that does not work is the environmental problem. You use the latest api17 it? Make sure adt is 22., And the need to rise to android-SDK build tools latest version 17.


Clean ---> Rebuild

Alternatively, you can manually import the package R is located. .
Reply:
The above has already been said, but added that the failure, you can delete the gen folder first and then clean it, then that is not a mistake, the wrong version may adt he did not look inside the error console, any general version What key expired or not, the wrong version, then click on the re-election version, if you ask the right key expired, deleted right after gen sometimes does not automatically give you generate, you just open a xml change it saved, You will generate a
Reply:
ADT provided directly by google, integrated inside eclipse no problem. No longer toss.

Thank you!
Reply:
Can not hide the status bar, wounding

No comments:

Post a Comment