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

  • Home
  • SEARCH
  • 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 9187247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:43:19+00:00 2026-06-17T19:43:19+00:00

I’m trying to search in an SQLite database and display the result in a

  • 0

I’m trying to search in an SQLite database and display the result in a ListView, but I can’t get the result that I want. It returns something like {1222233333,0909098886} which is not what I’m looking for. The result should be something like this, below each other on a listView:

1222233333

0909098886

The following code is in DBAdapter.

public ArrayList<String> getMeterNUmber1(String Date) throws SQLException
{
    String[] whereArgs = new String[]{Date};

    Cursor mCursor = db.rawQuery("SELECT MeterNumber FROM " + SCAN_TABLE + " WHERE  Date = ?",whereArgs);

    ArrayList<String> results = new ArrayList<String>();
    while (mCursor.moveToNext()) {
        results.add(mCursor.getString(0));
    }

    return results;
}

In this class I’m using sharedPreferences to store the result and pass it to the next class like this:

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putString("Shareusername",dbUser.getMeterNUmber1(ss).toStrin());
editor.commit();

This is how I’m trying to display the result in a ListView:

String sharedUsername;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
sharedUsername = settings .getString("Shareusername","null");

String [] value =  new String[] {sharedUsername};

listView = (ListView) findViewById(R.id.mylist);

pojoArrayList = new ArrayList<PojoClass>();
customerListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,value);
listView.setAdapter(customerListAdapter);

If there is something I’m doing wrong, please help me.

Log

01-18 21:17:44.405: E/AndroidRuntime(4249): FATAL EXCEPTION: main
01-18 21:17:44.405: E/AndroidRuntime(4249): java.lang.RuntimeException: Unable to start activity ComponentInfo{scann.barcode.scan/scann.barcode.scan.Result}: java.lang.NullPointerException
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.os.Looper.loop(Looper.java:137)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.ActivityThread.main(ActivityThread.java:5039)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at java.lang.reflect.Method.invokeNative(Native Method)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at java.lang.reflect.Method.invoke(Method.java:511)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at dalvik.system.NativeStart.main(Native Method)
01-18 21:17:44.405: E/AndroidRuntime(4249): Caused by: java.lang.NullPointerException
01-18 21:17:44.405: E/AndroidRuntime(4249):     at scann.barcode.scan.DBAdapter.getMeterNUmber1(DBAdapter.java:272)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at scann.barcode.scan.Result.onCreate(Result.java:58)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.Activity.performCreate(Activity.java:5104)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-18 21:17:44.405: E/AndroidRuntime(4249):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-18 21:17:44.405: E/AndroidRuntime(4249):     ... 11 more
  • 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-17T19:43:21+00:00Added an answer on June 17, 2026 at 7:43 pm

    You will need to split the string retrieved from SharedPreferences to a String array to show in ListView as:

    String[] value=sharedUsername.split(",");
    
    // Your code here...
    

    There is no need to store ArrayList in SharedPreferences, just store the date in SharedPreferences as:

    SharedPreferences settings =
        PreferenceManager.getDefaultSharedPreferences(
            getApplicationContext());
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("datestr",ss);
    editor.commit();
    

    And now retrieve data from the database using date when you want to show it in ListView as:

    String sharedUsername;
    SharedPreferences settings =
        PreferenceManager.getDefaultSharedPreferences(this);
    shareddate = settings .getString("datestr","null");
    
    ArrayList<String> sharedUsernamearr=null;
    if(shareddate !=null){
       sharedUsernamearr=dbUser.getMeterNUmber1(shareddate);
    }
    else{
      // Do your code here
    }
    
    listView = (ListView) findViewById(R.id.mylist);
    
    pojoArrayList = new ArrayList<PojoClass>();
    if(sharedUsernamearr !=null){
        customerListAdapter = new ArrayAdapter<String>(this,
                                      android.R.layout.simple_list_item_1,
                                      sharedUsernamearr);
        listView.setAdapter(customerListAdapter);
    }
    else{
        // Add your code here....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
i want to parse a xhtml file and display in UITableView. what is the
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.