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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:49:26+00:00 2026-06-06T17:49:26+00:00

i got some problems with my history listview. on logcat it stated the cause

  • 0

i got some problems with my history listview.
on logcat it stated the cause of the problem is new_item.

this is my code

c.mDbHelper.fetchAllNotes();
    Item new_item;    
for (i=0; i<c.getCount(); i++) {

    new_item.set(c.getString(1), c.getString(2), c.getInt(4), Uri.parse(c.getString(5)));
    item.add(new_item);
    c.moveToNext();
}

Item is a class I made. this is the set() method.

public void set(String name, String code, int qty, Uri imageuri){
    this.name = name;
    this.code = code;
    this.qty = qty;
    this.imageuri = imageuri;
}

this is my logcat

06-28 09:12:49.528: E/AndroidRuntime(818): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.avs.QRscanner/com.android.avs.QRscanner.ViewStock}: java.lang.NullPointerException
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.os.Looper.loop(Looper.java:123)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.ActivityThread.main(ActivityThread.java:3683)
06-28 09:12:49.528: E/AndroidRuntime(818):  at java.lang.reflect.Method.invokeNative(Native Method)
06-28 09:12:49.528: E/AndroidRuntime(818):  at java.lang.reflect.Method.invoke(Method.java:507)
06-28 09:12:49.528: E/AndroidRuntime(818):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-28 09:12:49.528: E/AndroidRuntime(818):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-28 09:12:49.528: E/AndroidRuntime(818):  at dalvik.system.NativeStart.main(Native Method)
06-28 09:12:49.528: E/AndroidRuntime(818): Caused by: java.lang.NullPointerException
06-28 09:12:49.528: E/AndroidRuntime(818):  at     com.android.avs.QRscanner.CustomAdapter.getCount(CustomAdapter.java:24)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.widget.ListView.setAdapter(ListView.java:454)
06-28 09:12:49.528: E/AndroidRuntime(818):  at com.android.avs.QRscanner.ViewStock.onCreate(ViewStock.java:36)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-28 09:12:49.528: E/AndroidRuntime(818):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-28 09:12:49.528: E/AndroidRuntime(818):  ... 11 more

DbHelper has 5 columns, which take string, string, string, int, string(for storing Uri)

thanks in advance for the help.

edit : add new_item to List item

  • 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-06T17:49:27+00:00Added an answer on June 6, 2026 at 5:49 pm

    Do you need to initialize new_item, i.e. (line 3 below)

    c.mDbHelper.fetchAllNotes();
    Item new_item;  // <-- Add this (thx jack57)
    for (i=0; i<c.getCount(); i++) {
     new_item = new Item();    // <-- Initialize here to prevent NullPointerException
     new_item.set(c.getString(1), c.getString(2), c.getInt(4), Uri.parse(c.getString(5)));
     c.moveToNext();
    }
    

    And you might want to use the Item object somewhere. Here it seems it is lost after the loop go to next i value.

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

Sidebar

Related Questions

I've got some problems. I've got this code: Dim infoID As Integer = objCommand1.ExecuteScalar()
I got some problems with this query i need all my selectors but i
I got some problems with my patterns. Hope somebody could help me with this.
I'm learning databases, using SQLce. Got some problems, with this error: A foreign key
I've got some problems with the following code in my PHP/MySQL application. It works
I've got some problems/misunderstandings with arrays in C++. int myArray[30]; myArray[1]=2; myArray[2]=4; This is
I got some problems with the following sql statement: $query= $this->db->get_where('navigation', 'linkname IS NOT
got some problems deploying a java web application on jboss 7.1... Stepped through the
I got some problems with EOF and stdio in a communication pipeline between a
I got some problems with the error Link error LNK2005 ... already defined. The

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.