返回语句不发送值显示

时间:2018-05-02 17:06:40

标签: java android

我的return语句不起作用,直到get语句(即set,变量等)的所有值都有效,如果强制显示有效的值。

  if (Pasta.isChecked() && Pork.isChecked() && Tomato.isChecked() && Carrots.isChecked() && TomatoPaste.isChecked()) {
                       // RecipeCodes recipe1 = new RecipeCodes();
                        //recipe1.setRecipeCode(1);
                        setRecipeCode(1);
                        getRecipecode();
                        //Recipecode = 1;
                        Log.i("INTERNAL CHECK", "RCODE ~" + Recipecode);
                        break;

 public void setRecipeCode(int C) {
    Recipecode = C;
    Log.i("SETRECIPECODETEST", "RECIPE CODE ~ " + Recipecode);
}


public int getRecipecode(){
   return Recipecode;
}

以下是基于" RecipeCode"显示的类的代码。变量

    Recipes temp = new Recipes();
    RecipeCodes RDisplay = new RecipeCodes();
    //temp.getRecipeCode();

    if(temp.getRecipecode() == 1){
        RDesc.setText("Italiano Sausage");
        //Log.i("WITHINIF","RCODE INTERNAL ~ " + temp.getRecipeCode());
    } else {
        RDesc.setText("test");
        //Log.i("TEST","RCODE WITHIN DISPLAY ~ " + RDisplay.getRecipeCode());
    }

(我已经完成了大量的编辑和评论,所以如果我的错误语法错误很少)。

1 个答案:

答案 0 :(得分:0)

这有效:

class Recipe {
    private int recipecode;

    public void setRecipeCode(int c) {
        recipecode = c;
    }

    public int getRecipecode() {
        return recipecode;
    }



    public static void main(String[] args)
    {
        Recipe temp = new Recipe();
        temp.setRecipeCode(1);
        System.out.println(temp.getRecipecode());
    }
}