Android中如何解决R' [英] How can resolve R in Android?

查看:210
本文介绍了Android中如何解决R'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被运行的程序猜测随机数,但在情况下的R,其应该是R 1不能被解析为一个变量错误出现许多时间。而我也尝试导入android.R;但不能没有无误工作。错误出现在为主或R.layout.main。所以请解决该问题。

I was run the program to guess random number but in case R, their should be "R cannot be resolved to a variable" error comes many time . And i am also try to import android.R; but could not work without errorless. error comes in to "main" or "R.layout.main". so please fix the problem.

public class GuessGame extends Activity {
    Button btnGuess;
   private EditText enter;
   private GuessGame mcontext;
   private Double guess;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final Random rand= new Random();
    final int numberToGuess= rand.nextInt(20);
    int numberOfTries=0;

        final boolean win= false;
        btnGuess= (Button)findViewById(R.id.btnGuess);
        enter= (EditText)findViewById(R.id.EnterNumber);

        TextView tv= (TextView) findViewById(R.id.dislpayResult);
        guess=new Double(enter.getText().toString());


     btnGuess.setOnClickListener(new OnClickListener() {
         private AlertDialog show;
         @Override
            public void onClick(View v) {
             while(win == false){
                 if((enter.getText().length() == 0) || (enter.getText().toString() == "")){

                     show= new AlertDialog.Builder(mcontext).setTitle("Error Was Found")
                        .setMessage("Input are Emppty")
                        .setPositiveButton("Ok", null).show();
            }
            else if(guess == numberToGuess){
                //win = true;
                Toast.makeText(GuessGame.this, "You have win", Toast.LENGTH_SHORT).show();
            }
            else if(guess < numberToGuess){
                Toast.makeText(GuessGame.this, "You guess is to low", Toast.LENGTH_SHORT).show();
            }
            else if(guess > numberToGuess){
                Toast t=Toast.makeText(GuessGame.this, "You guess is to high", Toast.LENGTH_SHORT);
                t.show();
            }
          }
        }
    });
    tv.setText("You win");
    tv.setText("Yhe Number was" + numberToGuess);
    tv.setText("Tries times" + numberOfTries);
   }

}

编辑:

Edited:

技巧来解决这个问题:

一旦你改变了你的资源,所有的名字,只是清理
  项目(Project>清洁..),等待几秒钟,和你的R.java文件
  会回家来。获取R.java文件备份应该摆脱
  大部分的错误,但如果没有,检查所有的类的进口
  对于进口android.R,如果它的存在,删除它并清洁
  项目。

Once you have changed all the names of your resources, just clean the project ( Project>Clean..), wait a few seconds, and your R.java file will come back home. Getting the R.java file back should get rid of most of your errors, but if it didn’t, check all your class’ imports for the "import android.R" and if it is there, delete it and clean the project.

详细信息解决方案,请访问:<一个href=\"http://google-androidlovers.blogspot.com/search/label/R%20cannot%20be%20resolved%20to%20a%20variable\"相对=nofollow>详细说明解决有关这篇文章

More details Solution go to : Details Solution about this article

推荐答案

在R.java文件应该自动生成的Andr​​oid。请尝试以下操作:

The R.java file should be automatically generated by Android. Try the following:


  1. 如果您使用的是Eclipse试试清洁工程,以重新生成该文件。

  2. 尝试修复没有涉及到R档的所有错误,然后重试项目清理选项。其他错误(例如,您的XML布局文件)摆摊通过项目清理R档的新版本。

  3. 确保您的项目是一个Android项目,你必须在你的类路径的文件的android.jar

这篇关于Android中如何解决R'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆