我实现监听器时出现语法错误

时间:2014-04-29 07:11:45

标签: android android-layout

我正在做一个应用程序,当我加载活动时从查询加载数据,我有一个按钮来加载其他查询。当我为按钮eclipse编写监听器时,会出现以下错误:syntax error on token(s), misplaced construct(s)。我为侦听器编写了构造函数方法,并且错误不会消失。如果我忘记添加一个},我会寻找,但我认为这一切都很接近。

这是活动的代码。

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class Examen extends Activity {
private TextView txtAsigExa;
private TextView txtTemaExa;
private TextView txtPreguntaExa;
private TextView txtRespuestaExa;
private Button btnVer;
private SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_examen);

    Bundle bundle = this.getIntent().getExtras();

    txtAsigExa=(TextView)findViewById(R.id.txtAsigExa);
    txtTemaExa=(TextView)findViewById(R.id.txtTemaExa);
    txtPreguntaExa=(TextView)findViewById(R.id.txtPreguntaExa);
    txtRespuestaExa=(TextView)findViewById(R.id.txtRespuestaExa);

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

     ExamenesSQLiteHelper ex4db=new ExamenesSQLiteHelper(this,"ExamenesDB",null,1);
    db=ex4db.getWritableDatabase();
    Cursor c=db.rawQuery("SELECT Preguntas.id Asignaturas.descripcion, Temas.descripcion, pregunta FROM Preguntas INNER JOIN Temas ON Preguntas.tema=Temas.id INNER JOIN Asignaturas ON Temas.id_as=Asignaturas.id WHERE tema='"+bundle.getString("Inicio")+"'",null);
    if(c.moveToFirst()){

      do{
            String cod=c.getString(0);
            String asignatura=c.getString(1);
            String tem=c.getString(2);
            String preg=c.getString(3);
            txtAsigExa.setText(asignatura);
            txtTemaExa.setText(tem);
            txtPreguntaExa.setText(preg);
        }while(c.moveToNext());
    }
    txtTemaExa.setText(bundle.getString("Inicio"));
    btnVer.setOnClickListener(new OnClickListener{
        public void onClick(View v){
            Cursor c1=db.rarQuery("SELECT respuesta FROM Preguntas WHERE id='"+cod+"'", null);
            if(c1.moveToFirst()){
                do{
                    String resp=c1.getString(0);
                    txtRespuestaExa.append(resp);
                }while(c1.moveToNext());
            }
        }
    });
}
}

1 个答案:

答案 0 :(得分:2)

您缺少方法括号:

btnVer.setOnClickListener(new OnClickListener{  

应该是:

btnVer.setOnClickListener(new OnClickListener(){