标记“上的语法错误”&引用;,预期的Java编程

标记“上的语法错误”&引用;,预期的Java编程,java,android,eclipse,token,Java,Android,Eclipse,Token,在Eclipse for android中编写代码时出现以下错误: 令牌“;”上出现语法错误,应为 及 这条线上有多个标记 - Syntax error on token ")", { expected after this token - Return type for the method is missing - Syntax error on token ".", ... expected - Syntax error, insert ";" to complete FieldDecla

在Eclipse for android中编写代码时出现以下错误:

令牌“;”上出现语法错误,应为

这条线上有多个标记

- Syntax error on token ")", { expected after this token
- Return type for the method is missing
- Syntax error on token ".", ... expected
- Syntax error, insert ";" to complete FieldDeclaration
我真的不明白为什么我很难弄清楚这是什么。Eclipse只说明哪里有错误,而不说明原因,而且它的“快速修复”永远不起作用。 请问,有人知道如何解决这个问题吗

 package com.example.apptest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
  private final String defaut = "Vous devez cliquer sur le bouton « Calculer l'IMC » pour obtenir un résultat.";
  private final String megaString = "Vous faites un poids parfait ! Wahou ! Trop fort ! On dirait Brad Pitt (si vous êtes un homme)/Angelina Jolie (si vous êtes une femme)/Willy (si vous êtes un orque) !";

  Button envoyer = null;
  Button raz = null;
  EditText poids = null;
  EditText taille = null;

  RadioGroup group = null;

  TextView result = null;

  CheckBox mega = null; /*Error here with the semicolon, eclipse wants a ','*/



    envoyer= (Button) findViewById(R.id.calcul); /*Long error here*/

    raz = (Button) findViewById(R.id.raz);

    taille = (EditText)findViewById(R.id.taille);
    poids = (EditText)findViewById(R.id.poids);

    mega = (CheckBox)findViewById(R.id.mega);

    group = (RadioGroup)findViewById(R.id.group);

    result = (TextView)findViewById(R.id.result);

    // On attribue un listener adapté aux vues qui en ont besoin
    envoyer.setOnClickListener(envoyerListener);
    raz.setOnClickListener(razListener);
    taille.addTextChangedListener(textWatcher);
    poids.addTextChangedListener(textWatcher);

    // Solution avec des onKey
    //taille.setOnKeyListener(modificationListener);
    //poids.setOnKeyListener(modificationListener);
    mega.setOnClickListener(checkedListener);
 }



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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

您的代码中有一个额外的<代码> } /Cuth>,因此您的<代码> OnCudio< <代码> >代码> OnCurrPoopOpStMeNu<代码>实际上不在您的代码>主活动< /代码>类

中。
 // your other code
   mega.setOnClickListener(checkedListener);
} //<---- End of MainActivity class

    @Override
    protected void onCreate(Bundle savedInstanceState) {
     ...
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    ...
    }

}// <--- should be actual end?
//您的其他代码
mega.setOnClickListener(checkedListener);

} //您在代码的中间有一个额外的<代码> } /Cuth>,因此您的<代码> OnCudio< <代码> >代码> OnCurePoopStMeNu/<代码>实际上不在您的代码>主活动< /代码>类

中。
 // your other code
   mega.setOnClickListener(checkedListener);
} //<---- End of MainActivity class

    @Override
    protected void onCreate(Bundle savedInstanceState) {
     ...
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    ...
    }

}// <--- should be actual end?
//您的其他代码
mega.setOnClickListener(checkedListener);

}你少了一些东西

  CheckBox mega = null;

     /***** Something missing here, don't you think? *******/
     // (hint: maybe an onResume() method declaration)

    envoyer= (Button) findViewById(R.id.calcul);

如果您仍然无法理解,请留下评论。

您缺少一些东西

  CheckBox mega = null;

     /***** Something missing here, don't you think? *******/
     // (hint: maybe an onResume() method declaration)

    envoyer= (Button) findViewById(R.id.calcul);

如果您仍然无法理解,请留下评论。

如果不在android活动中设置内容视图,则无法调用findViewById。所以你的代码应该是

 package com.example.apptest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
  private final String defaut = "Vous devez cliquer sur le bouton « Calculer l'IMC » pour obtenir un résultat.";
  private final String megaString = "Vous faites un poids parfait ! Wahou ! Trop fort ! On dirait Brad Pitt (si vous êtes un homme)/Angelina Jolie (si vous êtes une femme)/Willy (si vous êtes un orque) !";

  Button envoyer = null;
  Button raz = null;
  EditText poids = null;
  EditText taille = null;

  RadioGroup group = null;

  TextView result = null;

  CheckBox mega = null; /*Error here with the semicolon, eclipse wants a ','*/

//move your code from here


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

 // paste your moved code here
envoyer= (Button) findViewById(R.id.calcul); /*Long error here*/

    raz = (Button) findViewById(R.id.raz);

    taille = (EditText)findViewById(R.id.taille);
    poids = (EditText)findViewById(R.id.poids);

    mega = (CheckBox)findViewById(R.id.mega);

    group = (RadioGroup)findViewById(R.id.group);

    result = (TextView)findViewById(R.id.result);

    // On attribue un listener adapté aux vues qui en ont besoin
    envoyer.setOnClickListener(envoyerListener);
    raz.setOnClickListener(razListener);
    taille.addTextChangedListener(textWatcher);
    poids.addTextChangedListener(textWatcher);

    // Solution avec des onKey
    //taille.setOnKeyListener(modificationListener);
    //poids.setOnKeyListener(modificationListener);
    mega.setOnClickListener(checkedListener);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

如果不在android活动中设置内容视图,则无法调用findViewById。所以你的代码应该是

 package com.example.apptest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
  private final String defaut = "Vous devez cliquer sur le bouton « Calculer l'IMC » pour obtenir un résultat.";
  private final String megaString = "Vous faites un poids parfait ! Wahou ! Trop fort ! On dirait Brad Pitt (si vous êtes un homme)/Angelina Jolie (si vous êtes une femme)/Willy (si vous êtes un orque) !";

  Button envoyer = null;
  Button raz = null;
  EditText poids = null;
  EditText taille = null;

  RadioGroup group = null;

  TextView result = null;

  CheckBox mega = null; /*Error here with the semicolon, eclipse wants a ','*/

//move your code from here


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

 // paste your moved code here
envoyer= (Button) findViewById(R.id.calcul); /*Long error here*/

    raz = (Button) findViewById(R.id.raz);

    taille = (EditText)findViewById(R.id.taille);
    poids = (EditText)findViewById(R.id.poids);

    mega = (CheckBox)findViewById(R.id.mega);

    group = (RadioGroup)findViewById(R.id.group);

    result = (TextView)findViewById(R.id.result);

    // On attribue un listener adapté aux vues qui en ont besoin
    envoyer.setOnClickListener(envoyerListener);
    raz.setOnClickListener(razListener);
    taille.addTextChangedListener(textWatcher);
    poids.addTextChangedListener(textWatcher);

    // Solution avec des onKey
    //taille.setOnKeyListener(modificationListener);
    //poids.setOnKeyListener(modificationListener);
    mega.setOnClickListener(checkedListener);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

下面的代码在类内部浮动,没有合适的方法来保存它。只要将代码放在onCreate或任何其他方法中,您得到的错误就会得到解决

envoyer= (Button) findViewById(R.id.calcul); /*Long error here*/

raz = (Button) findViewById(R.id.raz);

taille = (EditText)findViewById(R.id.taille);
poids = (EditText)findViewById(R.id.poids);

mega = (CheckBox)findViewById(R.id.mega);

group = (RadioGroup)findViewById(R.id.group);

result = (TextView)findViewById(R.id.result);

// On attribue un listener adapté aux vues qui en ont besoin
envoyer.setOnClickListener(envoyerListener);
raz.setOnClickListener(razListener);
taille.addTextChangedListener(textWatcher);
poids.addTextChangedListener(textWatcher);

// Solution avec des onKey
//taille.setOnKeyListener(modificationListener);
//poids.setOnKeyListener(modificationListener);
mega.setOnClickListener(checkedListener);

下面的代码在类内部浮动,没有合适的方法来保存它。只要将代码放在onCreate或任何其他方法中,您得到的错误就会得到解决

envoyer= (Button) findViewById(R.id.calcul); /*Long error here*/

raz = (Button) findViewById(R.id.raz);

taille = (EditText)findViewById(R.id.taille);
poids = (EditText)findViewById(R.id.poids);

mega = (CheckBox)findViewById(R.id.mega);

group = (RadioGroup)findViewById(R.id.group);

result = (TextView)findViewById(R.id.result);

// On attribue un listener adapté aux vues qui en ont besoin
envoyer.setOnClickListener(envoyerListener);
raz.setOnClickListener(razListener);
taille.addTextChangedListener(textWatcher);
poids.addTextChangedListener(textWatcher);

// Solution avec des onKey
//taille.setOnKeyListener(modificationListener);
//poids.setOnKeyListener(modificationListener);
mega.setOnClickListener(checkedListener);

如果将此代码放置在适当的位置,则清理和构建应该可以工作。首先,请尝试Jigar的解决方案。然后尝试将
envoyer=(按钮)放入findViewById(R.id.calcul)onCreate()
中输入code>并查看它是否有效。您可以输入完整的类代码吗?有时日食可能表现得不稳定!所以不要失去希望。在发布的代码中,似乎没有任何错误(考虑R.id.calcul是有效的)。问题出在其他地方。您缺少整个方法的
{
}
位置。如果此代码放置在正确的位置,请首先尝试Jigar的解决方案。然后尝试将
envoyer=(按钮)放入findViewById(R.id.calcul)onCreate()
中输入code>并查看它是否有效。您可以输入完整的类代码吗?有时日食可能表现得不稳定!所以不要失去希望。在发布的代码中,似乎没有任何错误(考虑R.id.calcul是有效的)。问题出在其他地方。您缺少
{
}
整个方法的某个位置。