应用程序意外停止android studio(Settext Error)

时间:2015-06-06 09:59:45

标签: android

我有一个问题,当我使用settext时,应用程序意外停止了android studio。你能帮帮我吗?

package net.android.test;

import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class phuongtrinhb1 extends Activity {
Button giaibt;
    EditText nhapa,nhapb,ketqua;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phuongtrinhb1);
        giaibt = (Button)findViewById(R.id.giaibt);
        nhapa = (EditText)findViewById(R.id.nhapa);
        nhapb = (EditText)findViewById(R.id.nhapb);

        giaibt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                double a,b;
                a = Double.parseDouble(nhapa.getText().toString());
                b = Double.parseDouble(nhapb.getText().toString());

ketqua.setText("Test x ="+(-b/a));
            }
        });
    }
}

1 个答案:

答案 0 :(得分:1)

你还没有使用EditText ketqua:

例如

ketqua = (EditText)findViewById(R.id.ketqua);