Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:02:30+00:00 2026-06-11T04:02:30+00:00

i was using SQLiteHelper to store data in a database, data was correctly stored

  • 0

i was using SQLiteHelper to store data in a database, data was correctly stored (opened with SQLite viewer), but when i have to get data from DB, my code returns null values always

public class HistorySQLiteHelper extends SQLiteOpenHelper{

String sqlCreate = "CREATE TABLE History (artist TEXT, title TEXT, link TEXT)";

    public HistorySQLiteHelper(Context context, String nombre, CursorFactory factory, int version){
            super(context, nombre, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db){
            db.execSQL(sqlCreate);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int versionAnterior, int versioNueva){
            db.execSQL("DROP TABLE IF EXISTS History");
            db.execSQL(sqlCreate);
    }
}

And this is the code i use to retrieve data

 String[] fields = new String[] {"artist", "title", "link"};


                    HistorySQLiteHelper hdbh = new HistorySQLiteHelper(HistoryActivity.this, "DBHistory", null, 1);
                    SQLiteDatabase db = hdbh.getReadableDatabase();
                    Cursor c = db.query("History", fields, "artist=?", new String[]{String.valueOf(0)}, null, null, null);

                    int counter = 0;

                    artist = new String[30];
                    title = new String[30];
                    links = new String[30];

                    if (c.moveToFirst()) {
                            do {
                                    artist[counter] = c.getString(0);
                                    title[counter] = c.getString(1);
                                links[counter] = c.getString(2);
                                    counter++;
                            } while (c.moveToNext());
                    }
                    db.close();

       if (artist.length < 1){
            String[] strings = nee Stting[]{" No results. "};
                            adaptador = new ArrayAdapter<String>(HistoryActivity.this, android.R.layout.simple_list_item_1, strings);
                            list.setAdapter(adaptador);
               }else{
                            AdaptadorTitulares adapter = new AdaptadorTitulares(HistoryActivity.this);
                        list.setAdapter(adapter);
                    }
                    list.setClickable(true);
            }
    }

And ArrayAdapter class:

    class AdaptadorTitulares extends ArrayAdapter {

        Activity context;

        @SuppressWarnings("unchecked")
                AdaptadorTitulares(Activity context) {
                super(context, R.layout.listitem_titular, artist);
                this.context = context;
        }

        public View getView(int position, View convertView, ViewGroup parent)
        {
                        View item = convertView;
                        ViewHolder holder;

                if(item == null)
                {
                        LayoutInflater inflater = context.getLayoutInflater();
                        item = inflater.inflate(R.layout.listitem_titular, null);

                        holder = new ViewHolder();
                        holder.titulo = (TextView)item.findViewById(R.id.LblTitulo);

                        item.setTag(holder);
                }
                else
                {
                        holder = (ViewHolder)item.getTag();
                }

                        holder.titulo.setText(artist[position]);

                        return(item);
                }
    }

    static class ViewHolder {
        TextView titulo;
    }

Why does my code give null values and how to solve it?

PD: here are variable fields and onCreate method

public class HistoryActivity extends Activity{

private ListView list;
private String[] artist;
private String[] title;
private String[] links;
private ArrayAdapter<String> adaptador;

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_history);

    list = (ListView)findViewById(R.id.history_list); 

    new LoadTask().execute(); //this is where I put the code to retrieve data

} ////////////////////////////////       onCreate END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:02:32+00:00Added an answer on June 11, 2026 at 4:02 am

    Okay, I know which was my error. I declared Cursor like this:

    Cursor c = db.query("History", fields, "artist=?", new String[] {String.valueOf(0)}, null, null, null);
    

    With this, I only obtained those values with artists = "0".

    What I wanted to do was retrieve all values from all columns.. For that i had to declare 3rd and 4th params as null

    Cursor c = db.query("History", fields, null, null, null, null, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all im using a sqlite helper class, but i have a little problem
I am fetching data from an sqlite database to Android mobile in a listview.
Using Core Data, I have a fetch request to fetch the minimum of a
I have an SQLite3 Database (created in a desktop sqlite application), with the android_metadata
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Needing to store about 20,000 rows of information locally in SQLite Database. There are
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
Using the Redis info command, I am able to get all the stats of
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.