Monday, January 11, 2016

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




            


Today, setting up the android development environment, make a hello world program
eclipse generated code is 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 is: setContentView (R.layout.activity_main); in this line
R can not be resolved to a varialbel

I do not understand, how will eclipse generated skeleton code wrong? Really hurt people ah
Reply:
Because R document does not generate it, it may be not introduced R files.
You can clean up your project. The menu bar point project, then clean.
If that does not work is the environment in question. You use the latest api17 it? Make sure and adt is 22. android- SDK build tools need to rise to the latest version 17.
Reply:
clean under the project to try
Or you do not compile the result R is not generated
Reply:
clean look, if you still have problems, it may be wrong elsewhere in the project, leading to not automatically generate R.java
Reply:
Re-creating a new project and see good not good, or if not, it is to build environmental problems.
Reply:
quote 1 floor wlcw16 reply:
R file because it does not generate, it may not introduced R files.
You can clean up your project. The menu bar point project, then clean.
If that does not work is the environment in question. You use the latest api17 it? Make sure and adt is 22. android- SDK build tools need to rise to the latest version.

17
Clean --- & gt; Rebuild

Alternatively, you can manually import 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 at the console, there are given, generally available version What key expired or not, the wrong version, then on again choose what version, if the key has expired you ask it, right after deleted gen sometimes does not automatically give you generate, you just open a xml change it to save, it is will give you generate a
Reply:
ADT provided the direct use google, inside integrated eclipse is no problem. No toss.

thank you all!
Reply:
Unable to hide the status bar, wounding
Reply:
The import android.Rq pack removal on the line, guide the wrong package
Reply:
activity_main file in question to check

Reply:
quote 9th floor u011719228 reply:
The import android.Rq pack removal on the line, guide the wrong package



correct! !

No comments:

Post a Comment