0

Android用のEclipseでコーディング中にこのエラーが発生しました:

トークン ";" の構文エラー、予期される

この行に複数のマーカー

- 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;
}

}
4

4 に答える 4

1

以下のコードは、それを保持するための適切なメソッドなしで、クラス内に浮かんでいます。コードを 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);
于 2014-04-16T12:04:07.997 に答える
0

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;
}

}
于 2013-07-23T05:50:17.457 に答える
0

何かが足りない。

  CheckBox mega = null;

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

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

それでもわからない場合はコメントを残してください。

于 2013-07-23T03:19:43.837 に答える