0

I want to extract data from an ArrayList, but the LogCat shows null value.

My code is:

try {
   String sql = "SELECT Cname FROM demo";
   Statement stmt = con.createStatement();
   final ResultSet rs = stmt.executeQuery(sql);
   while (rs.next()) {
      arrData.add(rs.getString("Cname").toString());
   }
   Campaign campaign_data[] = new Campaign[] {
      new Campaign(R.drawable.empty, "Today:"+ arrData.indexOf(0)),
      new Campaign(R.drawable.empty, "This Month:" + arrData.indexOf(1))
   };
} catch() {
}
1
  • Please add more details Commented Jun 20, 2015 at 14:19

1 Answer 1

1

Is arrData of type ArrayList?

You seem to be calling indexOf(0) on it which is probably not what you want.

public int indexOf(Object o)

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.

I would assume you meant to call get(i), so try the following:

      new Campaign(R.drawable.empty, "Today:"+ arrData.get(0)),
      new Campaign(R.drawable.empty, "This Month:" + arrData.get(1))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.