• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to put the values of a table in SQLite db into a String array

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,
I'm programming by android. I have such the below line in one of my classes. I want that to put the elements of the values which I got from DB into a String array. How could I do this? I appreciate if anyone can help me.
thanks
// mysqlitehelper is an object that has methods which work with DB and my data.
List<Info_Table>values = mysqlitehelper.getAllInfo(30);
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I am not clear on your question. Do you mean that you already have a List<Info_Table> and you need to convert that into a String[]?

Then you would need to:
1) Create a new String array that is an appropriate size (same size as the List if you need one String for each Info_Table instance in the List)
2) Iterate over the List
3) For each Info_Table in the list, convert the Info_Table to a String
4) Assign the String thus created to the correct index in the String array

The difficult part is in step 3, but we can't help you with that since we don't know anything about the input and the expected output. It might be as simple as calling the .toString() method, or maybe you have to read values and build some result. You have to figure that part out on your own since you know what you have and what you want.
 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you undrstood my problem correctly. I wrote some code like below but it does't work. it seems that it doesn't go to for loop. I'm sure the values has elements.Could anyone help me to fix my problem please?


 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the for loop you use a variable named count: for (int i=0; i<count; i++) What is the value of count? Where does it get set? If you don't set it then the default value would be 0, and the for loop would not be executed.

p.s. I modified your post to add code tags. Pleas read this: UseCodeTags so your future posts with code in it will be displayed in a format easier to read.>
 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for your reply. count is the count of Info_Table elements that I wrote the method getInfoCount() in MySqlHelper class. I tested this method and it is correct. also I tested count variable and it shows correct number of Info elements in DB. so I'm sure that the problem is not related to count variable!


 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you need to do more debugging. What is the exact value of count before that loop gets executed? What are the values actually returned from the getAllInfo() method? What are the values actually entered in to the stringArrayList? What is the actual size of the stringArray? You can get all this through various means, such as running the application through a debugger with a well place break point, then stepping through the code, or by generous use of Log statements and viewing LogCat.

You probably don't need to store the stringArrayList and count as instance variables. In fact, you probably don't need to store them at all. Here is how I would simplify the code:


If you debug the code and it looks like the count and the values all look correct then you have to start looking at the Adapter and figure out how it is presenting the data.>
reply
    Bookmark Topic Watch Topic
  • New Topic