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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:09:24+00:00 2026-06-13T20:09:24+00:00

I have code to make list view like this class LoadAllProduct extends AsyncTask<String, String,

  • 0

I have code to make list view like this

 class LoadAllProduct extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(allproduct.this);
            pDialog.setMessage("Loading product. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        } 

        /**
         * getting All products from url
         * */
        protected String doInBackground(String... args) {
            Cursor cursor;

            int i=0;
            while(cursor.moveToNext()){
                id_produk[i] = cursor.getInt(0);
                String title = cursor.getString(1);
                //String price = cursor.getString(2);
                //String desc = cursor.getString(3);
                //String how_to = cursor.getString(4);
                String time = cursor.getString(5);
                path_image[i] = cursor.getString(7);

                Cursor cur = db.getProductLink(id_produk[i]);
                int y = 0;
                String link = "";
                while(cur.moveToNext()){
                    if(y == 0) link = cur.getString(0);
                    else link = link + "\n" + cur.getString(0);
                    y++;
                }
                product_item[i] = new MenuItem(title, link, time, path_image[i]);
                i++;
                cur.close(); 
            }   

            cursor.close();
            db.close();

            return null;

        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    mainlist.setAdapter(new ListMenuAdapter(product_item));
                }
            }); 
            pDialog.dismiss();
        }
}

and now , I want to show detail of my product with just click selection item of list view with this code

 mainlist.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting values from selected ListItem


                String pid = productList.get(position).get(TAG_PID);

                // Starting new intent
                Intent in = new Intent(getApplicationContext(),editproductActivity.class);

                // sending pid to next activity
                in.putExtra(TAG_PID, pid);  
                in.putExtra("phone", mPhoneNumber);
                in.putExtra("daftar", daftar);           
                startActivityForResult(in, 100);    
            }
        });
         }

And this log cat show this, and i Think error cause String pid = productList.get(position).get(TAG_PID);

11-06 12:46:25.305: ERROR/AndroidRuntime(1616): FATAL EXCEPTION: main
11-06 12:46:25.305: ERROR/AndroidRuntime(1616): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at java.util.ArrayList.get(ArrayList.java:311)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at shoop3.android.edu.allproduct$4.onItemClick(allproduct.java:175)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.widget.ListView.performItemClick(ListView.java:3382)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.os.Handler.handleCallback(Handler.java:587)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.os.Looper.loop(Looper.java:123)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at java.lang.reflect.Method.invoke(Method.java:521)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-06 12:46:25.305: ERROR/AndroidRuntime(1616):     at dalvik.system.NativeStart.main(Native Method)

can u help me ?? thanks

  • 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-13T20:09:25+00:00Added an answer on June 13, 2026 at 8:09 pm

    I think productList is empty add data in it, and then check.

    if(productList.size==0){
    
       System.out.println("list size is zero...");
       return;
    
     }
     String pid = productList.get(position).get(TAG_PID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that I want to make point-free; (\k t -> chr
I have this code and I need to make this work: if ($handle =
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
So i have this code which makes a box, but want to make the
My view model looks something like this: public class CarViewModel { public CarModel Car
I have the following code to make a jsonp call. var contacts; $.ajax({ url:
I have some html5 canvas code to make an image, the current fillstyle is
I have the following code where I make an copy of my database that
In YUI I have following code working for mouse wheel. How do I make

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.