gpt4 book ai didi

java - 在 Android 中从第 0 行 col -1 获取字段槽失败

转载 作者:行者123 更新时间:2023-12-02 06:24:23 25 4
gpt4 key购买 nike

我想检索 ListView 中特定id的所有数据。当我运行该应用程序时,我得到:

IllegalStateException : get field slot from row 0 column -1 failed

这是我的 Activity 代码。

dbAdapter=new DataBase_Adapter(New_Lead_Detail_Activity.this).open();
dataBase = dbAdapter.getDatabaseInstance();

String strSql = "SELECT name FROM " + DataBase_Adapter.TABLE_NEW_LEAD + " where id = '" +newleadId + "'";
System.out.println("sql =" + strSql);

cursor = dataBase.rawQuery(strSql , null);
System.out.println("Cursor" + cursor);

if (cursor.getCount() == 1 )
{
cursor.moveToFirst();

actions = new ArrayList<User_Action>();

String strOrgName=(cursor.getString(cursor.getColumnIndex(DataBase_Adapter.KEY_ORGANIZATION_NAME)));
if(strOrgName != null)
{
actions.add(new User_Action("Orgenization Name", strOrgName));
System.out.println("Orgenization Name = " + strOrgName);
}


String strName = (cursor.getString(cursor.getColumnIndex(DataBase_Adapter.KEY_NEW_LEAD_NAME)));
if(strName != null)
{
actions.add(new User_Action("Name", strName));
System.out.println("strName =" + strName);
}

String strEmail=(cursor.getString(cursor.getColumnIndex(DataBase_Adapter.KEY_NEW_LEAD_EMAIL)));
if(strEmail != null)
{
actions.add(new User_Action("Email ID", strEmail));
System.out.println("Email ID =" + strEmail);
}

String strMobile=(cursor.getString(cursor.getColumnIndex(DataBase_Adapter.KEY_NEW_LEAD_MOBILE)));
if(strMobile != null)
{
actions.add(new User_Action("Mobile", strMobile));
System.out.println("Mobile =" + strMobile);
}

String strProduct=(cursor.getString(cursor.getColumnIndex(DataBase_Adapter.KEY_NEW_LEAD_Product)));
if(strProduct != null)
{
actions.add(new User_Action("Product", strProduct));
System.out.println("Product =" + strProduct);
}

String strBudget=(cursor.getString(cursor.getColumnIndex(DataBase_Adapter.KEY_NEW_LEAD_BUDGET)));
if(strBudget != null)
{
actions.add(new User_Action("Budget", strBudget));
System.out.println("Budget =" + strBudget);
}

adapter = new Action_Adapter();
setListAdapter(adapter);

}

}

class Action_Adapter extends ArrayAdapter<User_Action>
{

Action_Adapter() {
super(New_Lead_Detail_Activity.this, R.layout.new_lead_detail_item, actions);
}


@Override
public View getView(int position, View convertView, ViewGroup parent)

{
User_Action action = actions.get(position);
LayoutInflater inflater = getLayoutInflater();

View view = inflater.inflate(R.layout.new_lead_detail_item, parent, false);

TextView label = (TextView) view.findViewById(R.id.label);
label.setText(action.getLabel());

TextView data = (TextView) view.findViewById(R.id.data);
data.setText(action.getData());

return view;
}

}

}

这是日志猫信息。

12-20 14:05:07.519: E/CursorWindow(9252): Bad request for field slot 0,-1. numRows = 1, numColumns = 1
12-20 14:05:07.559: E/AndroidRuntime(9252): FATAL EXCEPTION: main
12-20 14:05:07.559: E/AndroidRuntime(9252): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lead_management_project/com.lead_management_project.New_Lead_Detail_Activity}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.os.Looper.loop(Looper.java:123)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-20 14:05:07.559: E/AndroidRuntime(9252): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 14:05:07.559: E/AndroidRuntime(9252): at java.lang.reflect.Method.invoke(Method.java:507)
12-20 14:05:07.559: E/AndroidRuntime(9252): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-20 14:05:07.559: E/AndroidRuntime(9252): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-20 14:05:07.559: E/AndroidRuntime(9252): at dalvik.system.NativeStart.main(Native Method)
12-20 14:05:07.559: E/AndroidRuntime(9252): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.database.CursorWindow.getString_native(Native Method)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.database.CursorWindow.getString(CursorWindow.java:329)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
12-20 14:05:07.559: E/AndroidRuntime(9252): at com.lead_management_project.New_Lead_Detail_Activity.onCreate(New_Lead_Detail_Activity.java:69)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-20 14:05:07.559: E/AndroidRuntime(9252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-20 14:05:07.559: E/AndroidRuntime(9252): ... 11 more

最佳答案

需要更改您的查询

使用下面

"SELECT * FROM " + DataBase_Adapter.TABLE_NEW_LEAD + " where id = '" +newleadId + "'";

而不是

"SELECT name FROM " + DataBase_Adapter.TABLE_NEW_LEAD + " where id = '" +newleadId + "'";

关于java - 在 Android 中从第 0 行 col -1 获取字段槽失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20699521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com