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 3612340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:59:13+00:00 2026-05-18T21:59:13+00:00

Hey, I’m trying to implement a ListView on Android, which will print the data

  • 0

Hey, I’m trying to implement a ListView on Android, which will print the data retrieved from the SQLite Database. So I want to retrieve a lot of columns from the table and add this to a list, so I will print this list as a ListView.

For this I created a method that will select all the columns from the table in a separate class, and I will print the ListView in a ListActivity.

I want to retrieve 6 columns of the table, which is represented by the ids 2, 4, 5, 6, 7, 9.

But it shows a lot of errors:

12-24 19:19:04.066: ERROR/AndroidRuntime(22630): FATAL EXCEPTION: main
12-24 19:19:04.066: ERROR/AndroidRuntime(22630): java.lang.NullPointerException
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.AbsListView.obtainView(AbsListView.java:1418)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.ListView.makeAndAddView(ListView.java:1745)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.ListView.fillDown(ListView.java:670)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.ListView.fillFromTop(ListView.java:727)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.ListView.layoutChildren(ListView.java:1598)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.AbsListView.onLayout(AbsListView.java:1248)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.View.layout(View.java:7175)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.os.Looper.loop(Looper.java:123)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at android.app.ActivityThread.main(ActivityThread.java:3647)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at java.lang.reflect.Method.invokeNative(Native Method)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at java.lang.reflect.Method.invoke(Method.java:507)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-24 19:19:04.066: ERROR/AndroidRuntime(22630):     at dalvik.system.NativeStart.main(Native Method)

Here is the code of the method that select the data.

public List<String> selectAll() {

    List<String> list1 = new ArrayList<String>();
    List<String> list2 = new ArrayList<String>();
    List<String> list3 = new ArrayList<String>();
    List<String> list4 = new ArrayList<String>();
    List<String> list5 = new ArrayList<String>();
    List<String> list6 = new ArrayList<String>();

    Cursor cursor = this.db.query(TABLE_NAME, null, null, null, null, null,
            "duration desc");

    if (cursor.moveToFirst()) {
        do {

            list1.add(cursor.getString(2));
            list2.add(cursor.getString(4));
            list3.add(cursor.getString(5));
            list4.add(cursor.getString(6));
            list5.add(cursor.getString(7));
            list6.add(cursor.getString(9));

            list1.addAll(list2);
            list1.addAll(list3);
            list1.addAll(list4);
            list1.addAll(list5);
            list1.addAll(list6);

        } while (cursor.moveToNext());
        Log.i(TAG, "After cursor.moveToNext()");
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    Log.i(TAG, "Before selectAll returnment");
    return list1;
}

And here is the code of the ListActivity class:

public class RatedCalls extends ListActivity {

private static final String LOG_TAG = "RatedCallsActivity";
private CallDataHelper cdh;
StringBuilder sb = new StringBuilder();
OpenHelper openHelper = new OpenHelper(RatedCalls.this);

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    Log.i(LOG_TAG, "calling from onCreate()");

    cdh = new CallDataHelper(this);

    Log.i(LOG_TAG, "--->>> before calling the service");
    startService(new Intent(this, RatedCallsService.class));
    Log.i(LOG_TAG, "Service called.");
    Log.i(LOG_TAG, "--->>> after calling the service");
    fillList();

}

public void fillList() {

    List<String> ratedCalls = this.cdh.selectAll();

    setListAdapter(new ArrayAdapter<String>(this, R.layout.listitem,
            ratedCalls));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(),
                    ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
    }
  • 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-05-18T21:59:14+00:00Added an answer on May 18, 2026 at 9:59 pm

    The problem was that in the database if the column value was empty, the cursor returned null, so, that was the JavaNullPointerException. So If there was no contact name to insert in the database, I inserted an empty string. That works!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.