我遇到了多个复选框的问题。情况是这样的,我有5个复选框,当我检查其中两个时,一个活动将开始,但如果我检查其他两个活动将开始。我的问题是当我检查checkbox1时我的应用程序崩溃了。如果您有任何想法,请成为我的客人:)
package com.example.matematikanapredna;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class Pravougaonik extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pravougaonik);
final CheckBox checkbox1=(CheckBox) findViewById(R.id.checkBox1);
final CheckBox checkbox2=(CheckBox) findViewById(R.id.CheckBox01);
final CheckBox checkbox3=(CheckBox) findViewById(R.id.checkBox2);
final CheckBox checkbox4=(CheckBox) findViewById(R.id.checkBox3);
final CheckBox checkbox5=(CheckBox) findViewById(R.id.checkBox4);
Button nastavi=(Button) findViewById(R.id.button1);
nastavi.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkbox1.isChecked()==true && checkbox2.isChecked()==true) {
Intent i=new Intent (v.getContext(), PravougaonikStranica.class);
startActivity(i);
checkbox1.toggle();
checkbox2.toggle();
}
}
});
}
}
这里也是logcat输出:
07-11 14:26:13.507: I/Process(26961): Sending signal. PID: 26961 SIG: 9
07-11 14:27:45.067: D/dalvikvm(28468): GC_FOR_ALLOC freed 68K, 6% free 12194K/12867K, paused 30ms, total 30ms
07-11 14:27:45.072: I/dalvikvm-heap(28468): Grow heap (frag case) to 13.031MB for 614416-byte allocation
07-11 14:27:45.107: D/dalvikvm(28468): GC_CONCURRENT freed 1K, 6% free 12793K/13511K, paused 17ms+2ms, total 35ms
07-11 14:27:45.107: D/dalvikvm(28468): WAIT_FOR_CONCURRENT_GC blocked 10ms
07-11 14:27:45.122: D/dalvikvm(28468): GC_FOR_ALLOC freed 0K, 6% free 12793K/13511K, paused 15ms, total 15ms
07-11 14:27:45.127: I/dalvikvm-heap(28468): Grow heap (frag case) to 14.072MB for 1093136-byte allocation
07-11 14:27:45.152: D/dalvikvm(28468): GC_CONCURRENT freed 0K, 6% free 13860K/14599K, paused 15ms+3ms, total 29ms
07-11 14:27:45.152: D/dalvikvm(28468): WAIT_FOR_CONCURRENT_GC blocked 11ms
07-11 14:27:45.247: D/libEGL(28468): loaded /system/lib/egl/libEGL_mali.so
07-11 14:27:45.257: D/libEGL(28468): loaded /system/lib/egl/libGLESv1_CM_mali.so
07-11 14:27:45.262: D/libEGL(28468): loaded /system/lib/egl/libGLESv2_mali.so
07-11 14:27:45.267: D/(28468): Device driver API match
07-11 14:27:45.267: D/(28468): Device driver API version: 10
07-11 14:27:45.267: D/(28468): User space API version: 10
07-11 14:27:45.267: D/(28468): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
07-11 14:27:45.302: D/OpenGLRenderer(28468): Enabling debug mode 0
07-11 14:27:47.007: E/SpannableStringBuilder(28468): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
07-11 14:27:47.007: E/SpannableStringBuilder(28468): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
07-11 14:27:47.747: D/AndroidRuntime(28468): Shutting down VM
07-11 14:27:47.747: W/dalvikvm(28468): threadid=1: thread exiting with uncaught exception (group=0x418622a0)
07-11 14:27:47.762: E/AndroidRuntime(28468): FATAL EXCEPTION: main
07-11 14:27:47.762: E/AndroidRuntime(28468): java.lang.IllegalStateException: Could not find a method onCheckboxClicked(View) in the activity class com.example.matematikanapredna.Pravougaonik for onClick handler on view class android.widget.CheckBox with id 'checkBox1'
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.view.View$1.onClick(View.java:3678)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.view.View.performClick(View.java:4211)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.widget.CompoundButton.performClick(CompoundButton.java:105)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.view.View$PerformClick.run(View.java:17267)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.os.Handler.handleCallback(Handler.java:615)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.os.Looper.loop(Looper.java:137)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-11 14:27:47.762: E/AndroidRuntime(28468): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 14:27:47.762: E/AndroidRuntime(28468): at java.lang.reflect.Method.invoke(Method.java:511)
07-11 14:27:47.762: E/AndroidRuntime(28468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-11 14:27:47.762: E/AndroidRuntime(28468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-11 14:27:47.762: E/AndroidRuntime(28468): at dalvik.system.NativeStart.main(Native Method)
07-11 14:27:47.762: E/AndroidRuntime(28468): Caused by: java.lang.NoSuchMethodException: onCheckboxClicked [class android.view.View]
07-11 14:27:47.762: E/AndroidRuntime(28468): at java.lang.Class.getConstructorOrMethod(Class.java:460)
07-11 14:27:47.762: E/AndroidRuntime(28468): at java.lang.Class.getMethod(Class.java:915)
07-11 14:27:47.762: E/AndroidRuntime(28468): at android.view.View$1.onClick(View.java:3671)
07-11 14:27:47.762: E/AndroidRuntime(28468): ... 12 more
答案 0 :(得分:0)
错误消息(LogCat输出)将非常有用。 你有没有尝试清理你的项目?有时候R.java搞砸了,导致了ClassCastExceptions ......