我有一个关于员工表单的数据库,当我传递员工电子邮件 ID 时,我需要获取员工详细信息。我无法获取详细信息,我参考了这个链接 获取带有光标的单行和这个链接。
我的代码
数据库代码
public List<String> getContact(String eid) {
List<String> labels = new ArrayList<String>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor= db.query(TABLE_EMPLOY, new String[] {KEY_EMAIL,"email"}, "email=?",new String[]{eid}, null, null, null);
if (cursor != null){
do{
cursor.moveToFirst();
labels.add(cursor.getString(1));
} while (cursor.moveToNext());
}cursor.close();
db.close();
// returning lables
return labels;
}
活动代码
dataBase db = new dataBase(this);
List<String> studentInfo = db.getContact(eid);
for (String cn : studentInfo){
Toast.makeText(getApplicationContext(),cn.toString(), Toast.LENGTH_LONG).show();
}
错误日志
09-06 16:56:27.330: E/AndroidRuntime(21699): FATAL EXCEPTION: main
09-06 16:56:27.330: E/AndroidRuntime(21699): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.ActivityThread.access$1300(ActivityThread.java:123)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.os.Looper.loop(Looper.java:137)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-06 16:56:27.330: E/AndroidRuntime(21699): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 16:56:27.330: E/AndroidRuntime(21699): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 16:56:27.330: E/AndroidRuntime(21699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-06 16:56:27.330: E/AndroidRuntime(21699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-06 16:56:27.330: E/AndroidRuntime(21699): at dalvik.system.NativeStart.main(Native Method)
09-06 16:56:27.330: E/AndroidRuntime(21699): Caused by: java.lang.NullPointerException
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
09-06 16:56:27.330: E/AndroidRuntime(21699): at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
09-06 16:56:27.330: E/AndroidRuntime(21699): ... 11 more
编辑 当我传递电子邮件 ID 我需要获取 ID、姓名、昵称、用户名、密码、手机号