**Here im trying to confirm that if a value is found so that i can move to the next page.**
public void onClick(View arg0) {
sqlStuff search1 = new sqlStuff(search_page.this);
switch (arg0.getId()) {
case R.id.search_button:
boolean found = false;
String Systname = editText1.getText().toString();
String[] IDSysNames = search1.getIDSysName();
for(int i = 0; i < IDSysNames.length; i++)
{
if(Systname.equals(IDSysNames[i].toString()))
{
found = true;
number = i;
}
}
if(found==true)
{
Intent search = new Intent("com.MC.ChemPal.RESULT");
startActivity(search);
}
else
{
Dialog d = new Dialog(this);
d.setTitle("result not found");
TextView tv = new TextView(this);
d.setContentView(tv);
d.show();
}
break;
这是我尝试获取以下值的部分
public String[] getIDSysName()
{
String[] result = new String[0];
try
{
String[] columns = new String[] {KEY_SYSNAME };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
int iSysName = c.getColumnIndex(KEY_SYSNAME);
int i = 0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
i++;
}
result = new String[i];
i = 0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result[i] = c.getString(iSysName);
String lk = null;
Log.d(lk, result[i]);
i++;
}
}
catch(Exception e)
{
String tr = null;
Log.e(tr, e.getMessage());
}
return result;
}
此代码应该检查我的数据库中的值,如果找到它,请转到下一页。但是我不断收到我添加的未找到值的对话框。我已经检查过该值是否存在,因为我也有一个数据库视图代码。
日志猫。
FATAL EXCEPTION:MAIN
java.lang.NullPointerException:println needs a message
at android.util.Log.printlnNative(Native Method)
at android.util.Log.e(Log.java:230)
at com.MC.ChemPal.SqlDStuff.getIDSysName(sqlStuff.java.153)
at com.MC.ChemPal.search_page.onClick(search_page.java:42)
at android.view.View.performClick(View.java.2485)
at android.view.View$PerformClick.run(View.java.9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(zygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)