对不起,我是安卓新手
我有 2 个EditTexts和 1 个按钮,当我按下按钮时,将打印 EditTexts 的值,但我给出了错误
XML:
<Button
android:id="@+id/submit"
android:layout_width="212dp"
android:layout_height="wrap_content"
android:layout_x="52dp"
android:layout_y="337dp"
android:text="@string/Submit"
android:onClick="submit" />
<EditText
android:id="@+id/quantity"
android:layout_width="182dp"
android:layout_height="wrap_content"
android:layout_x="9dp"
android:layout_y="86dp"
android:ems="10" />
<EditText
android:id="@+id/Unit"
android:layout_width="182dp"
android:layout_height="wrap_content"
android:layout_x="11dp"
android:layout_y="15dp"
android:ems="10" >
<requestFocus />
</EditText>
Java 类是:
public class add extends Activity
{
private static String[] montharray;
Button mButton;
EditText Unit;
EditText quantity;
private int days;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
Unit =(EditText) findViewById(R.id.unit);
quantity =(EditText) findViewById(R.id.quantity);
mButton =(Button) findViewById(R.id.submit);
}
public void submit(View view)
{
System.out.println("Unit= "+Unit.getText().toString()+" quantity= "+quantity.getText().toString());
}
}
这是错误:
05-16 15:37:35.857: E/AndroidRuntime(17951): FATAL EXCEPTION: main
05-16 15:37:35.857: E/AndroidRuntime(17951): java.lang.IllegalStateException: Could not execute method of the activity
...
05-16 15:37:35.857: E/AndroidRuntime(17951): Caused by: java.lang.NullPointerException
05-16 15:37:35.857: E/AndroidRuntime(17951): at net.learn2develop.UsingIntent.add.submit(add.java:56)
我启动所有对象,什么是 java.lang.NullPointerException?