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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:06:48+00:00 2026-06-13T06:06:48+00:00

i getting NPE on my listview..so when i click button, its show the data

  • 0

i getting NPE on my listview..so when i click button, its show the data that i have set on another form..

here is my custom adapter code :

public class AdapterListPemesananMenu extends BaseAdapter {
    public static ArrayList<MenuInputClass> searchArrayList;

    private LayoutInflater mInflater;

    public AdapterListPemesananMenu(Context context, ArrayList<MenuInputClass> results) {
        searchArrayList = results;
        mInflater = LayoutInflater.from(context);
    }   


    public AdapterListPemesananMenu(OnClickListener onClickListener,
            ArrayList<MenuInputClass> searchResults) {
        // TODO Auto-generated constructor stub
    } 


    public int getCount() {
        return searchArrayList.size(); *********************the NPE is here
    }

    public Object getItem(int position) {
        return searchArrayList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_pemesananmenu_row, null);
            holder = new ViewHolder();
            holder.txtName = (TextView) convertView.findViewById(R.id.txtNamaMasuk);
            holder.txtCityState = (TextView) convertView
                    .findViewById(R.id.txtJumlahMasuk);


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

        holder.txtName.setText(searchArrayList.get(position).getNama_menu());
        holder.txtCityState.setText(searchArrayList.get(position)
                .getJumlah_menu());


        return convertView;
    }

    static class ViewHolder {
        TextView txtName;
        TextView txtCityState;

    }
}

this is my activity code:

public class SingleListView_Activity extends Activity{

    Button order;       
    public static ListView list_pemesanan;    
    public static String nama_menu;
    TextView namamenu;
    public static String jumlah_menu;
    EditText jumlahmenu;  
    //public static ArrayList<MenuInputClass> searchResults = GetSearchResults();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_view);  

        ListView list_single_list_view=(ListView)findViewById(R.id.list_single);    
        list_pemesanan = (ListView)findViewById(R.id.list);
        namamenu=(TextView)findViewById(R.id.nama_menu2);
        jumlahmenu = (EditText)findViewById(R.id.txtJumlahOrder);

        order=(Button)findViewById(R.id.btn_order);
        //when this button on click its set the data to my another form
        order.setOnClickListener(new OnClickListener() { 
                @Override
                public void onClick(View v) {                                             

                     ArrayList<MenuInputClass> searchResults = GetSearchResults();              
                      ListPemesanan_Activity.list_pemesanan.setAdapter(new AdapterListPemesananMenu(this,searchResults));   

                }

             });


    }

     private ArrayList<MenuInputClass> GetSearchResults(){
     //this is the data that i set
         ArrayList<MenuInputClass> results = new ArrayList<MenuInputClass>();

         MenuInputClass sr = new MenuInputClass();      
         sr.setJumlah_menu("asdas");
         sr.setNama_menu("2");
         results.add(sr);                
         return results;
        }
}

logcat :

10-23 04:33:19.759: E/AndroidRuntime(14459): FATAL EXCEPTION: main
10-23 04:33:19.759: E/AndroidRuntime(14459): java.lang.NullPointerException
10-23 04:33:19.759: E/AndroidRuntime(14459):    at list_pemesananmenu_view.AdapterListPemesananMenu.getCount(AdapterListPemesananMenu.java:35)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.widget.ListView.setAdapter(ListView.java:479)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at list_pemesananmenu_view.SingleListView_Activity$1.onClick(SingleListView_Activity.java:123)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.view.View.performClick(View.java:2538)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.view.View$PerformClick.run(View.java:9152)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.os.Handler.handleCallback(Handler.java:587)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.os.Looper.loop(Looper.java:130)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at android.app.ActivityThread.main(ActivityThread.java:3693)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at java.lang.reflect.Method.invokeNative(Native Method)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at java.lang.reflect.Method.invoke(Method.java:507)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
10-23 04:33:19.759: E/AndroidRuntime(14459):    at dalvik.system.NativeStart.main(Native Method)
10-23 04:33:19.769: E/(195): Dumpstate > /data/log/dumpstate_app_error
10-23 04:33:20.059: E/AudioPolicyManager(129): stopOutput stream = 1 , mHardwareOutput = 1, output = 1 

anyhelp would be appreciated…THANK YOU!!

  • 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-13T06:06:50+00:00Added an answer on June 13, 2026 at 6:06 am
    order.setOnClickListener(new OnClickListener() { 
       @Override
       public void onClick(View v) {                                             
          ArrayList<MenuInputClass> searchResults = GetSearchResults();              
          ListPemesanan_Activity.list_pemesanan.setAdapter(new AdapterListPemesananMenu(this,searchResults));   
       }
    });
    

    In the above code, you are calling new AdapterListPemesananMenu(OnClickListener onClickListener, ArrayList searchResults);

    “this” refers to OnClickListener, not the activity in this case, since you are inside the new OnClickListener() block.

    That constructor doesn’t initialize your searchArrayList. searchArrayList only gets initialized in your constructor that takes (Context, ArrayList).

    If you wanted to keep the rest of the code the same, you can probably do

    ListPemesanan_Activity.list_pemesanan.setAdapter(new AdapterListPemesananMenu(getApplicationContext(), searchResults));   
    

    and also get rid of the AdapterListPemesananMenu constructor that takes OnClickListener as a parameter to avoid confusion.

    That’s the quick fix/analysis of the NPE, there may be better ways to rearrange your code for what you are trying to achieve.

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

Sidebar

Related Questions

Alright, I've been getting a NPE that I can't figure out and it's driving
I am getting NPE here: Color base = UIManager.getColor(inactiveCaptionBorder); while UIManager.setLookAndFeel(com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel); is set to
For deleting the app data i am trying to use reflection but getting NPE
Hello stackoverflow community, I'm getting a NPE in my getView method of my custom
I'm getting a really strange NPE exception. This is the offending code: private static
Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have
Getting red warning message that expected identifier for this statement CALayer = ImageView.layer; Using
I have the following SQL that I am having problems converting to HQL. A
Getting the following error, which I understand and have seen before. But one thing
Getting an error with my code found HERE ... Which is a culmination of

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.