0

我按下按钮时遇到问题

如果有人能帮助我,我真的很感激

public class submit implements Button.OnClickListener {
    @Override
    public void onClick(View v) {

        no = " "+noper.getText();
        na = " "+nama.getText();

        if (rb1.isChecked())
            j = " Male ";
        if (rb2.isChecked())
            j = " Female ";

        ag = (String) agamalist.getSelectedItem();  

        tl = (String) Spinner01.getSelectedItem() + "-"
                + (String) Spinner02.getSelectedItem() + "-"
                + (String) Spinner03.getSelectedItem();

        ju = "";
        if (c1.isChecked())
            ju += " TK ";
        if (c2.isChecked())
            ju += " SI ";
        if (c3.isChecked())
            ju += " TE ";

        t1.setText(no);
        t2.setText(na);
        t3.setText(j);
        t4.setText(ag);
        t5.setText(tl);
        t6.setText(ju);

        tabHost.setCurrentTab(1);
    }
}

程序正确启动,但是当我按下按钮时,不幸的是并关闭了我的程序。

这是原木猫

11-11 06:52:18.298: I/Choreographer(1879): Skipped 166 frames!  The application may be doing too much work on its main thread.
11-11 06:52:18.328: D/gralloc_goldfish(1879): Emulator without GPU emulation detected.
11-11 06:52:19.138: I/Choreographer(1879): Skipped 161 frames!  The application may be doing too much work on its main thread.
11-11 06:52:23.799: I/Choreographer(1879): Skipped 33 frames!  The application may be doing too much work on its main thread.
11-11 06:52:25.649: D/AndroidRuntime(1879): Shutting down VM
11-11 06:52:25.649: W/dalvikvm(1879): threadid=1: thread exiting with uncaught exception (group=0x41465700)
11-11 06:52:25.739: E/AndroidRuntime(1879): FATAL EXCEPTION: main
11-11 06:52:25.739: E/AndroidRuntime(1879): java.lang.NullPointerException
11-11 06:52:25.739: E/AndroidRuntime(1879):     at com.IrvanKosini.kuis1.MainActivity$submit.onClick(MainActivity.java:100)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at android.view.View.performClick(View.java:4240)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at android.view.View$PerformClick.run(View.java:17721)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at android.os.Handler.handleCallback(Handler.java:730)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at android.os.Looper.loop(Looper.java:137)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at android.app.ActivityThread.main(ActivityThread.java:5103)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at java.lang.reflect.Method.invokeNative(Native Method)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at java.lang.reflect.Method.invoke(Method.java:525)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-11 06:52:25.739: E/AndroidRuntime(1879):     at dalvik.system.NativeStart.main(Native Method)
11-11 06:52:27.999: I/Process(1879): Sending signal. PID: 1879 SIG: 9
4

2 回答 2

0

你的类应该实现 View.OnClickListener,实现抽象方法 OnClick 来做任何你想做的事情。在 onCreate() 方法中还将监听器设置为按钮:

myButton.setOnClickListener(this);
于 2013-11-11T12:16:50.253 回答
0

OMG ...你为什么要创建一个完整的班级..?

你也可以用一种简短而甜蜜的方法来做到这一点。

btn.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {
          // do your work here
     }
});
于 2013-11-16T13:44:53.683 回答