查看RadioGroup的问题?

时间:2016-03-09 10:43:36

标签: android

好的,所以我更多地搜索了这个问题,确实存在一个不同的问题。所以,我的应用程序崩溃说:应用程序意外停止。我确实发现仅当我单击XML文件中分配给无线电组的空间时才会出现问题。你能告诉我我的问题在哪里吗?

我试着在这里发布logcat的错误:

"

03-09 12:14:47.330: E/AndroidRuntime(285): FATAL EXCEPTION: main

03-09 12:14:47.330: E/AndroidRuntime(285): java.lang.IllegalStateException: Could not find a method (View) in the activity class com.example.scoala.AndroidQuiz for onClick handler on view class android.widget.RadioGroup with id 'opcoes'

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.view.View$1.onClick(View.java:2059)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.view.View.performClick(View.java:2408)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.view.View$PerformClick.run(View.java:8816)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.os.Handler.handleCallback(Handler.java:587)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.os.Handler.dispatchMessage(Handler.java:92)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.os.Looper.loop(Looper.java:123)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.app.ActivityThread.main(ActivityThread.java:4627)

03-09 12:14:47.330: E/AndroidRuntime(285):  at java.lang.reflect.Method.invokeNative(Native Method)

03-09 12:14:47.330: E/AndroidRuntime(285):  at java.lang.reflect.Method.invoke(Method.java:521)

03-09 12:14:47.330: E/AndroidRuntime(285):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

03-09 12:14:47.330: E/AndroidRuntime(285):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

03-09 12:14:47.330: E/AndroidRuntime(285):  at dalvik.system.NativeStart.main(Native Method)

03-09 12:14:47.330: E/AndroidRuntime(285): Caused by: java.lang.NoSuchMethodException: 

03-09 12:14:47.330: E/AndroidRuntime(285):  at java.lang.ClassCache.findMethodByName(ClassCache.java:308)

03-09 12:14:47.330: E/AndroidRuntime(285):  at java.lang.Class.getMethod(Class.java:985)

03-09 12:14:47.330: E/AndroidRuntime(285):  at android.view.View$1.onClick(View.java:2052)

03-09 12:14:47.330: E/AndroidRuntime(285):  ... 11 more"

以下是该课程的一些代码:

package com.example.scoala;

import com.example.scoala.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.TextView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class AndroidQuiz extends Activity {
    int acertos = 0;

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

    iniciarRodada(1);
}

public void iniciarRodada(int numero){
    Perguntas question = new Perguntas();
    RadioGroup radiogroup = (RadioGroup) findViewById(R.id.opcoes);
    question.op1 = (RadioButton) findViewById(R.id.op1);
    question.op2 = (RadioButton) findViewById(R.id.op2);
    question.op3 = (RadioButton) findViewById(R.id.op3);
    question.pergunta = (TextView) findViewById(R.id.pergunta);

    if(numero == 1){
        question.rodada1();
        question.op1.setOnClickListener(listenerRodada1);
        question.op2.setOnClickListener(listenerRodada1);
        question.op3.setOnClickListener(listenerRodada1);
    } else if(numero == 2){
        question.rodada2();
        question.op1.setOnClickListener(listenerRodada2);
        question.op2.setOnClickListener(listenerRodada2);
        question.op3.setOnClickListener(listenerRodada2);
    } else if(numero == 3){
        question.rodada3();
        question.op1.setOnClickListener(listenerRodada3);
        question.op2.setOnClickListener(listenerRodada3);
        question.op3.setOnClickListener(listenerRodada3);

private OnClickListener listenerRodada1 = new OnClickListener() {
        public void onClick(View v) {
            RadioButton r = (RadioButton) v;
            String resposta = (String) r.getText();
            r.setChecked(false);
            if(resposta == "mentine in functiune luminile de întalnire reduce viteza de deplasare si opreste daca este cazul"){
                acertos++;
                Toast.makeText(getApplicationContext(),"Corect",Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(),"Gresit",Toast.LENGTH_SHORT).show();
            }

        iniciarRodada(2);
    }
};
private OnClickListener listenerRodada2 = new OnClickListener() {
    public void onClick(View v) {
        RadioButton r = (RadioButton) v;
        String resposta = (String) r.getText();
        r.setChecked(false);
        if(resposta == "nerespectarea semnalelor politistilor la trecerea coloanelor oficiale"){
            acertos++;
            Toast.makeText(getApplicationContext(),"Corect",Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getApplicationContext(),"Gresit",Toast.LENGTH_SHORT).show();
        }

        iniciarRodada(3);
    }
};
private OnClickListener listenerRodada3 = new OnClickListener() {
    public void onClick(View v) {
        RadioButton r = (RadioButton) v;
        String resposta = (String) r.getText();
        r.setChecked(false);
        if(resposta == "pe drumurile nationale europene"){
            acertos++;
            Toast.makeText(getApplicationContext(),"Corect",Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getApplicationContext(),"Gresit",Toast.LENGTH_SHORT).show();
        }
            @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.android_quiz, menu);
    return true;
 }

}                          
你能帮我吗?万分感谢!

0 个答案:

没有答案