-1
這是我得到 致命異常錯誤:主要光標初始化錯誤:列值始終在-1內容提供商
Process: com.example.yaamu.survey_contentprovider, PID: 17250
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yaamu.survey_contentprovider/com.example.yaamu.survey_contentprovider.Database_Activitry}: java.lang.IllegalStateException: Couldn't read row 3, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalStateException: Couldn't read row 3, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at android.database.CursorWrapper.getString(CursorWrapper.java:137)
at com.example.yaamu.survey_contentprovider.Database_Activitry.onCreate(Database_Activitry.java:33)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
這是屬性設置 /******** ******數據庫表 列**************************************** */
public static final String TABLE_DATABASE = "database_table";
public static final String COLUMN_DB_QUEST_ID = "question_question_id";
public static final String COLUMN_DB_SURVEYID = " survey_id";
public static final String COLUMN_QUESTION = " question_ques";
public static final String COLUMN_TYPE_OF_ANSWER = "type_of_answer";
public static final String COLUMN_IS_VALIDATION = "is_validation";
public static final String COLUMN_ANSWER_TYPE_FILTER = "answer_type_filter";
public static final String COLUMN_IS_REQUIRED = "is_required";
public static final String COLUMN_IS_SHUFFLE = "is_shuffle";
public static final String COLUMN_LINEAR_MIN_VALUE = "linear_min_value";
public static final String COLUMN_LINEAR_MAX_VALUE = "linear_max_value";
public static final String COLUMN_LINEAR_MIN_LABEL = "linear_min_label";
public static final String COLUMN_LINEAR_MAX_LABEL = "linear_max_label";
public static final String COLUMN_RATING_VALUE = "rating_value";
/**********************************************************************************************/
並創建表。
private static final String DATABASE_TABLE_CREATE = " create table "
+ TABLE_DATABASE + "("
+ COLUMN_DB_QUEST_ID + " integer primary key autoincrement, "
+ COLUMN_DB_SURVEYID + " integer not null, "
+ COLUMN_QUESTION + " text not null, "
+ COLUMN_TYPE_OF_ANSWER + " text not null, "
+ COLUMN_IS_VALIDATION + " boolean, "
+ COLUMN_ANSWER_TYPE_FILTER + " text, "
+ COLUMN_IS_REQUIRED + " boolean not null,"
+ COLUMN_IS_SHUFFLE + " boolean, "
+ COLUMN_LINEAR_MIN_VALUE + " integer, "
+ COLUMN_LINEAR_MAX_VALUE + " integer, "
+ COLUMN_LINEAR_MIN_LABEL + " text,"
+ COLUMN_LINEAR_MAX_LABEL + " text, "
+ COLUMN_RATING_VALUE + " integer);";
該值已添加。它顯示在烤麪包的消息,但我不能檢索值
我用另一個活動來獲取值
Cursor c=getContentResolver().query(SurveyContentProvider.CONTENT_URI3, null, null, null, SurveyContentProvider.COLUMN_DB_QUEST_ID);
if(c!=null & c.getCount()>0)
{
c.moveToFirst();
while(c.moveToNext()){
text1.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_DB_QUEST_ID)));
text2.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_DB_SURVEYID)));
text3.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_QUESTION)));
text4.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_TYPE_OF_ANSWER)));
text5.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_IS_VALIDATION)));
text6.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_ANSWER_TYPE_FILTER)));
text7.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_IS_REQUIRED)));
text8.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_IS_SHUFFLE)));
text9.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_LINEAR_MIN_VALUE)));
text10.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_LINEAR_MAX_VALUE)));
text11.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_LINEAR_MIN_LABEL)));
text12.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_LINEAR_MAX_LABEL)));
text13.setText(c.getString(c.getColumnIndex(SurveyContentProvider.COLUMN_RATING_VALUE)));
}
}
THANK YOU
即使不起作用,使用c.moveToFirst()而不是c.moveToPosition(2) – akhilesh0707
@ akhilesh0707! – Yashaswini
你想要取哪一行..?僅第三排..? –