有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从Android中的Bean类获取空值?

下面是我在Bean类中插入数据和在ArrayList中插入Bean类的方法,但是当我试图从Bean getter方法中获取值时,我得到的是空值

     public ArrayList<QuestionBean> GetClickedIdImagesQuranHadeesBean(String topic_id)
{ ArrayList<QuestionBean> questionImageNameList = new ArrayList<QuestionBean>();

          String [] splits = topic_id.split("-");
          Integer [] realNumbers = new Integer [splits.length];

          String sqlSelect = "SELECT topic_question.id,topic_question.question_image_name,topic.topic_name,topic_question.topic_id  FROM topic_question,topic WHERE topic.id=topic_question.topic_id AND topic_question.topic_id IN ";
          String whereStatement = "(";
          for (int i = 0; i<splits.length; i++)
          {
              realNumbers[i] = Integer.parseInt(splits[i]);
              whereStatement += realNumbers[i]+((i == splits.length -1) ? "" :",");

          }
          whereStatement += ");";

          sqlSelect += whereStatement + "ORDER BY topic_question.topic_id";

          Cursor cursor = database.rawQuery(sqlSelect,null);
          Log.i("Cursor Query Print:",""+sqlSelect);
          if(cursor != null) {
            cursor.moveToFirst();

            while (!cursor.isAfterLast()) {
            Log.d("cursor",""+cursor);
            QuestionBean questionBeanInstance = new QuestionBean();
            questionBeanInstance.setQuestionId(cursor.getInt(0));
            Log.d("questionBeanInstance id",""+cursor.getInt(0));
            questionBeanInstance.setQuestionImageName(cursor.getString(1));
            Log.d("questionBeanInstance QuestionImageName",""+cursor.getString(1));
            questionBeanInstance.setQuestionTopicName(cursor.getString(2));
            Log.d("questionBeanInstance setQuestionTopicName",""+cursor.getString(2));
            questionBeanInstance.setQuestionTopicId(cursor.getInt(3));
            Log.d("questionBeanInstance setQuestionTopicId",""+cursor.getInt(3));
            questionImageNameList.add(questionBeanInstance);

                }
            } else {
                Log.d("", "Cursor is Null");
                Log.d("retrieving all parameters", "count < 0");
            }

            cursor.close();
            return questionImageNameList;
        }

//当我试图从bean类中获取值时,我得到的是空值。有人能告诉我我做错了什么吗

private void GetQuestionDataForQuranHadeesBean(String clickedTopicIdString)
    {
        ArrayList<QuestionBean> questionImagesNameList = new ArrayList<QuestionBean>();
        questionImagesNameList = AndroidUtil.externalDb.GetClickedIdImagesQuranHadeesBean(clickedTopicIdString);
        Log.i("questionImagesNameList:",""+questionImagesNameList + ":::id:"
                + clickedTopicIdString);
        for (int i = 0;i < questionImagesNameList.size();i++) {
            QuestionBean ques = new QuestionBean();
            final TableRow questionTableRow = (TableRow) inflator.inflate(
                    R.layout.questions_table_row, null);
            ImageView questionImageView = (ImageView) questionTableRow
                    .findViewById(R.id.questionImageView);
            Log.i("ques.getQuestionImageName()",""+ques.getQuestionImageName());
            Log.i("ques.getQuestionTopicId",""+ques.getQuestionTopicId());
            Log.i("ques.getQuestionTopicName",""+ques.getQuestionTopicName());

} 这些行返回空值:

Log.i("ques.getQuestionImageName()",""+ques.getQuestionImageName());
            Log.i("ques.getQuestionTopicId",""+ques.getQuestionTopicId());
            Log.i("ques.getQuestionTopicName",""+ques.getQuestionTopicName());

而列表中的数据如下所示: 这一行的日志是:

Log.i("questionImagesNameList:",""+questionImagesNameList + ":::id:"
                + clickedTopicIdString);

Logcat

02-15 14:02:29.705: I/questionImagesNameList:(360): [QuestionBean [questionId=1, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Quran, questionTopicId=0], QuestionBean [questionId=2, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Quran, questionTopicId=0], QuestionBean [questionId=3, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Quran, questionTopicId=0], QuestionBean [questionId=4, questionImageName=quran_o_hadees_question_4, questionTopicName=Quran, questionTopicId=0], QuestionBean [questionId=5, questionImageName=quran_o_hadees_question_5, questionTopicName=Quran, questionTopicId=0], QuestionBean [questionId=6, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=7, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=8, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=9, questionImageName=quran_o_hadees_question_4, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=10, questionImageName=quran_o_hadees_question_5, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=11, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=12, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=13, questionImageName=quran_o_hadess_ques1.png, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=14, questionImageName=quran_o_hadees_question_4, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=15, questionImageName=quran_o_hadees_question_5, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=16, questionImageName=quran_o_hadees_question_6, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=17, questionImageName=quran_o_hadees_question_7, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=18, questionImageName=quran_o_hadees_question_8, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=19, questionImageName=quran_o_hadees_question_9, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=20, questionImageName=quran_o_hadees_question_10, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=21, questionImageName=quran_o_hadees_question_11, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=22, questionImageName=quran_o_hadees_question_12, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=23, questionImageName=quran_o_hadees_question_13, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=24, questionImageName=quran_o_hadees_question_14, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=25, questionImageName=quran_o_hadees_question_15, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=26, questionImageName=quran_o_hadees_question_16, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=27, questionImageName=quran_o_hadees_question_17, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=28, questionImageName=quran_o_hadees_question_18, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=29, questionImageName=quran_o_hadees_question_19, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=30, questionImageName=quran_o_hadees_question_20, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=31, questionImageName=quran_o_hadees_question_21, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=32, questionImageName=quran_o_hadees_question_22, questionTopicName=Hadees, questionTopicId=1], QuestionBean [questionId=33, questionImageName=quran_o_hadees_question_6, questionTopicName=Quran, questionTopicId=0], QuestionBean [questionId=34, questionImageName=quran_o_hadees_question_7, questionTopicName=Quran, q


共 (1) 个答案

  1. # 1 楼答案

    试试这个

      for (int i = 0;i < questionImagesNameList.size();i++) {
                QuestionBean ques = questionImagesNameList.get(i);
               //...........
      }