2つの列のデータをデータベースからとにフェッチしていString Array
ますInt Array
。そして、テキストビューにデータを表示しようとしています。しかし、それは表示されておらず、いくつかのエラーがあります。配列に入ってくるが表示されていないデータ。
私のコードは以下の通りです
try
{
mydatabase=this.openOrCreateDatabase("testdata", MODE_PRIVATE, null);
Cursor c=mydatabase.rawQuery("SELECT DISTINCT name,MAX(user_score) AS max_score FROM "+TableName+" WHERE user_score IS NOT NULL GROUP BY name ORDER BY max_score DESC LIMIT 3" , null);
int column1=c.getColumnIndex("name");
int column2=c.getColumnIndex("max_score");
c.moveToFirst();
if(c!=null)
{ int i=0;
do
//for(int i=0;c.moveToNext();i++)
{
String Name=c.getString(column1);
int Score=c.getInt(column2);
Data[i]=Name;
Data1[i]=Score;
/*Data[1]=Name;
Data1[1]=Score;*/
System.out.println("i:"+i+"Data[i]:"+Data[i]+"Data1[i]:"+Data1[i]);
System.out.println("name"+Name+" score"+Score);
i++;
}while(c.moveToNext());
TextView tv=(TextView)findViewById(R.id.tv);
TextView points=(TextView)findViewById(R.id.points);
TextView tv1=(TextView)findViewById(R.id.tv1);
TextView points1=(TextView)findViewById(R.id.points1);
tv.setText(Data[0]);
points.setText(Data1[0]);
tv1.setText(Data[1]);
points1.setText(Data1[1]);
setContentView(main);
}
私のLogcatは:
06-04 13:40:35.761: E/ERROR(1347): android.content.res.Resources$NotFoundException: String resource ID #0x9a
06-04 13:40:35.761: E/ERROR(1347): at android.content.res.Resources.getText(Resources.java:201)
06-04 13:40:35.761: E/ERROR(1347): at android.widget.TextView.setText(TextView.java:2817)
06-04 13:40:35.761: E/ERROR(1347): at com.k_trivia_cricket.com.high_score.onCreate(high_score.java:76)
06-04 13:40:35.761: E/ERROR(1347): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-04 13:40:35.761: E/ERROR(1347): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-04 13:40:35.761: E/ERROR(1347): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-04 13:40:35.761: E/ERROR(1347): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-04 13:40:35.761: E/ERROR(1347): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-04 13:40:35.761: E/ERROR(1347): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 13:40:35.761: E/ERROR(1347): at android.os.Looper.loop(Looper.java:123)
06-04 13:40:35.761: E/ERROR(1347): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-04 13:40:35.761: E/ERROR(1347): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 13:40:35.761: E/ERROR(1347): at java.lang.reflect.Method.invoke(Method.java:521)
06-04 13:40:35.761: E/ERROR(1347): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-04 13:40:35.761: E/ERROR(1347): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-04 13:40:35.761: E/ERROR(1347): at dalvik.system.NativeStart.main(Native Method)