0
我的日誌貓。Sqlite無法執行活動的方法
09-27 21:00:42.414: E/AndroidRuntime(29268): FATAL EXCEPTION: main
09-27 21:00:42.414: E/AndroidRuntime(29268): java.lang.IllegalStateException: Could not execute method
of the activity
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.view.View$1.onClick(View.java:3609)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.view.View.performClick(View.java:4102)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.view.View$PerformClick.run(View.java:17085)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.os.Handler.handleCallback(Handler.java:615)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.os.Looper.loop(Looper.java:155)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.app.ActivityThread.main(ActivityThread.java:5511)
09-27 21:00:42.414: E/AndroidRuntime(29268): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 21:00:42.414: E/AndroidRuntime(29268): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 21:00:42.414: E/AndroidRuntime(29268): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
09-27 21:00:42.414: E/AndroidRuntime(29268): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
09-27 21:00:42.414: E/AndroidRuntime(29268): at dalvik.system.NativeStart.main(Native Method)
09-27 21:00:42.414: E/AndroidRuntime(29268): Caused by: java.lang.reflect.InvocationTargetException
09-27 21:00:42.414: E/AndroidRuntime(29268): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 21:00:42.414: E/AndroidRuntime(29268): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 21:00:42.414: E/AndroidRuntime(29268): at android.view.View$1.onClick(View.java:3604)
09-27 21:00:42.414: E/AndroidRuntime(29268): ... 11 more
09-27 21:00:42.414: E/AndroidRuntime(29268): Caused by: java.lang.NullPointerException
09-27 21:00:42.414: E/AndroidRuntime(29268): at
com.shikkhok.taskmanagement.MainActivity.save(MainActivity.java:38)
,這是我的MainActivity
public class MainActivity extends Activity {
EditText etName, etEmail, etPhone, etDesignation;
DatabaseHelper dbHelper;
// declare view
ListView lvEmployees;
// declare adapter
CustomizedAdapter adapter;
// datasource
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etName = (EditText) findViewById(R.id.etName);
etEmail = (EditText) findViewById(R.id.etEmail);
lvEmployees = (ListView) findViewById(R.id.lvEmployees);
dbHelper = new DatabaseHelper(this);
}
public void save(View v) {
String name = etName.getText().toString();
String email = etEmail.getText().toString();
String phone = etPhone.getText().toString();
String designation = etDesignation.getText().toString();
Employee employee = new Employee(name, email, phone, designation);
Toast.makeText(getApplicationContext(), employee.toString(),
Toast.LENGTH_LONG).show();
long inserted = dbHelper.insertEmployee(employee);
if (inserted >= 0) {
Toast.makeText(getApplicationContext(), "Data inserted",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Data insertion failed...",
Toast.LENGTH_LONG).show();
}
}
public void view(View v) {
ArrayList<Employee> employees = dbHelper.getAllEmployees();
if (employees != null && employees.size() > 0) {
adapter = new CustomizedAdapter(this, employees);
lvEmployees.setAdapter(adapter);
}
}
}
當我按下保存按鈕,此logcat的錯誤顯示在我的Eclipse如何解決它。
What's line MainActivity.java:38? – 2014-09-27 15:17:59
我不知道。 什麼是錯誤@ MysticMagic – 2014-09-27 15:22:24
這不是一個正確的答案,錯誤發生在Emloyee約束器中。 Thnx。@ MysticMagic – 2014-09-27 17:15:44