0

我正在将数据库中的两列数据提取String ArrayInt 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)
4

2 回答 2

2

原因:

您正在传递 int,因为此函数被称为http://developer.android.com/reference/android/widget/TextView.html#setText(int)

你需要传递字符串所以显示... http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence)

回答 :

正如我在评论 points.setText(Data1[0]+""); 作为字符串而不是 res id 传递...

于 2012-06-04T08:47:49.110 回答
1

根据您的错误日志,

未找到 TextView 资源“android.content.res.Resources$NotFoundException”。要解决它,请检查休闲,1-:您是否在 xml 文件中提到了该 textview 的 id。2-:对于一个以上的资源,可能有相同的 ID。

我希望它对你有充分的帮助。

于 2012-06-04T08:45:06.317 回答