单击时按钮错误

时间:2013-11-11 11:28:03

标签: android eclipse sdk

按下按钮

时出现问题

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

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

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

这是log cat

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

2 个答案:

答案 0 :(得分:0)

您的类应实现View.OnClickListener,实现抽象方法OnClick以执行您想要的任何操作。在onCreate()方法中,还将侦听器设置为按钮:

myButton.setOnClickListener(this);

答案 1 :(得分:0)

OMG ......你为什么要创建一个全班......?

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

btn.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {
          // do your work here
     }
});