Я не могу заставить EditText
работать в классе, который не является деятельностью.Я получаю ошибку трассировки стека:
02-29 10:07:00.742: E/AndroidRuntime(1108): FATAL EXCEPTION: main
02-29 10:07:00.742: E/AndroidRuntime(1108): java.lang.IllegalStateException: Could not execute method of the activity
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.view.View$1.onClick(View.java:2683)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.view.View.performClick(View.java:3110)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.view.View$PerformClick.run(View.java:11934)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.os.Handler.handleCallback(Handler.java:587)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.os.Handler.dispatchMessage(Handler.java:92)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.os.Looper.loop(Looper.java:132)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.app.ActivityThread.main(ActivityThread.java:4123)
02-29 10:07:00.742: E/AndroidRuntime(1108): at java.lang.reflect.Method.invokeNative(Native Method)
02-29 10:07:00.742: E/AndroidRuntime(1108): at java.lang.reflect.Method.invoke(Method.java:491)
02-29 10:07:00.742: E/AndroidRuntime(1108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-29 10:07:00.742: E/AndroidRuntime(1108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-29 10:07:00.742: E/AndroidRuntime(1108): at dalvik.system.NativeStart.main(Native Method)
02-29 10:07:00.742: E/AndroidRuntime(1108): Caused by: java.lang.reflect.InvocationTargetException
02-29 10:07:00.742: E/AndroidRuntime(1108): at java.lang.reflect.Method.invokeNative(Native Method)
02-29 10:07:00.742: E/AndroidRuntime(1108): at java.lang.reflect.Method.invoke(Method.java:491)
02-29 10:07:00.742: E/AndroidRuntime(1108): at android.view.View$1.onClick(View.java:2678)
02-29 10:07:00.742: E/AndroidRuntime(1108): ... 11 more
02-29 10:07:00.742: E/AndroidRuntime(1108): Caused by: java.lang.NullPointerException
02-29 10:07:00.742: E/AndroidRuntime(1108): at com.lifeApp.RegisterProcessing.createUser(RegisterProcessing.java:57)
02-29 10:07:00.742: E/AndroidRuntime(1108): at com.lifeApp.RegisterActivity.onClick(RegisterActivity.java:69)
02-29 10:07:00.742: E/AndroidRuntime(1108): ... 14 more
Мой код: У меня есть блок в кавычках строка ошибки
public void createUser(View v) {
Date cal=Calendar.getInstance().getTime();
EditText firstname = (EditText) v.findViewById(R.id.firstname);
EditText lastname = (EditText) v.findViewById(R.id.lastname);
EditText email = (EditText) v.findViewById(R.id.email);
EditText phone = (EditText) v.findViewById(R.id.phone);
EditText address = (EditText) v.findViewById(R.id.address);
EditText password = (EditText) v.findViewById(R.id.password);
EditText confPassword = (EditText) v.findViewById(R.id.confPassword);
//need to error check!!
ContentValues values = new ContentValues();
Log.i("firstname", ""+firstname.getText().toString());
values.put(MySQLiteHelper.COLUMN_FIRSTNAME, firstname.getText().toString());
values.put(MySQLiteHelper.COLUMN_LASTNAME, lastname.getText().toString());
values.put(MySQLiteHelper.COLUMN_EMAIL, email.getText().toString());
values.put(MySQLiteHelper.COLUMN_PHONE, phone.getText().toString());
values.put(MySQLiteHelper.COLUMN_ADDRESS, address.getText().toString());
values.put(MySQLiteHelper.COLUMN_PASSWORD, password.getText().toString());
values.put(MySQLiteHelper.COLUMN_DATE, cal.toLocaleString());
long insertId = database.insert(MySQLiteHelper.TABLE_REGISTER, null,
values);
// To show how to query
Cursor cursor = database.query(MySQLiteHelper.TABLE_REGISTER,
registerColumns, MySQLiteHelper.COLUMN_ID + " = ?", new String[] {""+insertId},
null, null, null);
cursor.moveToFirst();
//return cursorToREgister(cursor,policyId);
}