これがコーディングです
<Button
android:id="@+id/conv"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Convert"
android:onClick="onCreate"/>
public class LstActivity extends Activity {
EditText et;
TextView tv;
Button b1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText)findViewById(R.id.editText1);
Spinner spinner=(Spinner)findViewById(R.id.spinner1);
Spinner s2=(Spinner)findViewById(R.id.spinner2);
ArrayAdapter<?> adapter=ArrayAdapter.createFromResource(this, R.array.weight, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new myaction());
tv=(TextView)findViewById(R.id.textView3);
ArrayAdapter<?> adapter1=ArrayAdapter.createFromResource(this, R.array.weight, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter1);
s2.setOnItemSelectedListener(new myaction2());
b1=(Button)findViewById(R.id.conv);
et.setText("0");
float x=(Float.parseFloat(String.valueOf(et.getText())));
if ((spinner.getSelectedItemPosition()==2) && ((s2.getSelectedItemPosition()==1)))
{
tv.setText(String.valueOf(gmtomilli(x)+"mg"));
}
}
アプリは正常に起動しますが、ボタンをクリックすると、次のエラーが表示されます。
06-21 15:48:46.509: E/AndroidRuntime(2260): java.lang.IllegalStateException: Could not find a method onCreate(View) in the activity class kk.and.LstActivity for onClick handler on view class android.widget.Button with id 'conv'