1

I'm trying to make an app for my parents business, but at this point I found a problem.

I'm trying to get some strings from a SQLite database and to store them into an array.

I'm trying this:

            //This opens the db
            SQLManager info = new SQLManager(this);
            info.open();              

            String[] data = {"", "", "", ""};

            for (int i = 1; i == 3; i++)
            {
                data[i]=(info.getProduct(i));
            }

            info.close();
            tv.setText(data[0]);
            tv.setText(data[1]);
            tv.setText(data[2]);

info.getproduct is a method which gets a string from the database. This works fine. The problem is that i can't update the value of the array. It always shows the same.

Any idea?

6 Answers 6

5

You Do This,

  String[] data = new String[4];

        for (int i = 0; i <data .length; i++)
        {
            data[i]=(info.getProduct(i));
        }

It Helps You.

Sign up to request clarification or add additional context in comments.

Comments

0

you should do this

String[] data = {"", "", "", ""};

            for (int i = 0; i <data .length; i++)
            {
                data[i]=(info.getProduct(i));
            }

Comments

0

the use of for loop is like this

for(initializatin;condition;increment)

while in your case it is not condition it is a statement, so work on it.

you can change to for (int i = 1; i <= 3; i++)

Comments

0

The second argument in the for loop is supposed to work as a while-condition, meaning the loop will run while it is true, as i starts as 1 it will not be 3 and thus the loop terminates at once. You probably want a loop that looks like this:

for( int i = 1; i<=3; i++ ){ //Are you sure you want to start from 1? The first element in an array has index 0.
    //Loop
}

Comments

0

this loop will never run you should change it to:

for(int i =0;i<3;i++){
}

Comments

-1

not i==3, use i<3 in the for loop

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.