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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:10:15+00:00 2026-06-09T03:10:15+00:00

How to avoid the ArrayIndexOutOfBoundsExceptions.in the pgm myval and myvals is ArrayList Global Variables.i

  • 0

How to avoid the ArrayIndexOutOfBoundsExceptions.in the pgm myval and myvals is ArrayList Global Variables.i think i covert the GlobalVariable , ArrayList to String[] is only the pbm.plz help me .

    public class TicketActivity extends Activity{
TextView t1;
TextView t2;
ListView l1;
TextView t6;
  public void onCreate(Bundle savedInstanceState){
   super.onCreate(savedInstanceState);
  setContentView(R.layout.ticket);
  t1=(TextView)findViewById(R.id.textView3);
  t2=(TextView)findViewById(R.id.textView5);
   l1=(ListView)findViewById(R.id.listView1);

     //Get the Table no Value From Edit Text


   Intent i1=getIntent();
   Bundle b=i1.getExtras();
    int num=b.getInt("Table No:");
    String pno=Integer.toString(num);
    t1.setText(pno);

        //Get The Guest Value From Edit Text

    Intent i2=getIntent();
    Bundle b1=i2.getExtras();
    int num1=b1.getInt("Guest:");
    String pno1=Integer.toString(num1);
    t2.setText(pno1);



    l1.setAdapter(new EfficientAdapter(TicketActivity.this));

   } 
   private static class EfficientAdapter extends BaseAdapter{
    private LayoutInflater mInflater;



    public EfficientAdapter(Context context){
        mInflater=LayoutInflater.from(context);

    // implementation of EfficientAdapter   
    }
    public int getCount() {

        return HomeActivity.select1.length;

    }
    public Object getItem(int position) {

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

        return position ;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        String[] stockArr = new String[GlobalClass.myval.size()];
        stockArr = GlobalClass.myval.toArray(stockArr);
        String[] stockArr1=new String[GlobalClass.myvals.size()];
        stockArr1=GlobalClass.myvals.toArray(stockArr1);
    if(convertView==null){
            convertView=mInflater.inflate(R.layout.list_ticket, null);
            holder=new ViewHolder();
            holder.Text1=(TextView)          convertView.findViewById(R.id.textView1);
            holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
            holder.Text3=(TextView) convertView.findViewById(R.id.textView3);
            convertView.setTag(holder);
        }
        else{
              holder=(ViewHolder)convertView.getTag();
            }

            holder.Text2.setText(stockArr[position]);
            holder.Text3.setText(stockArr1[position]);
            return convertView;

     }

    }
    static class ViewHolder{
        TextView Text1;
        TextView Text2;
        TextView Text3;

    }
      }

LogCat output:

   08-03 10:50:59.417: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:50:59.497: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
   08-03 10:52:22.737: I/dalvikvm(807): threadid=3: reacting to signal 3
   08-03 10:52:23.076: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
   08-03 10:52:23.236: I/dalvikvm(807): threadid=3: reacting to signal 3
   08-03 10:52:23.387: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:52:23.507: W/System.err(807): java.lang.NullPointerException
    08-03 10:52:23.537: W/System.err(807):  at com.eConnect.Restaurant.HomeActivity.onCreate(HomeActivity.java:142)
   08-03 10:52:23.537: W/System.err(807):   at android.app.Activity.performCreate(Activity.java:4465)
   08-03 10:52:23.647: W/System.err(807):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
   08-03 10:52:23.647: W/System.err(807):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
   08-03 10:52:23.681: W/System.err(807):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
   08-03 10:52:23.696: W/System.err(807):   at android.app.ActivityThread.access$600(ActivityThread.java:123)
   08-03 10:52:23.696: W/System.err(807):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
   08-03 10:52:23.728: W/System.err(807):   at android.os.Handler.dispatchMessage(Handler.java:99)
    08-03 10:52:23.736: W/System.err(807):  at android.os.Looper.loop(Looper.java:137)
    08-03 10:52:23.776: W/System.err(807):  at android.app.ActivityThread.main(ActivityThread.java:4424)
    08-03 10:52:23.776: W/System.err(807):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-03 10:52:23.797: W/System.err(807):  at java.lang.reflect.Method.invoke(Method.java:511)
    08-03 10:52:23.797: W/System.err(807):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    08-03 10:52:23.827: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:52:24.107: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:52:24.196: W/System.err(807):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
     08-03 10:52:24.196: W/System.err(807):     at dalvik.system.NativeStart.main(Native Method)
    08-03 10:52:24.257: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:52:24.269: D/dalvikvm(807): GC_CONCURRENT freed 100K, 3% free 9379K/9607K, paused 11ms+9ms
    08-03 10:52:24.427: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:52:24.790: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:52:24.938: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:52:25.267: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:52:25.447: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
     08-03 10:52:25.786: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:52:25.939: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:52:26.286: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:52:26.477: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:53:13.687: I/System.out(807): Length of Breakfast:12
     08-03 10:53:13.687: I/System.out(807): Length of P2:12
    08-03 10:53:15.837: I/System.out(807): Values[2EGG W/MEAT]
    08-03 10:53:15.837: I/System.out(807): Values[$ 4.7]
    08-03 10:53:17.248: I/System.out(807): Values[2EGG W/MEAT, BLUEBERRY CAKE]
    08-03 10:53:17.248: I/System.out(807): Values[$ 4.7, $ 3.0]
    08-03 10:53:21.317: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:53:21.467: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:53:21.817: I/dalvikvm(807): threadid=3: reacting to signal 3
    08-03 10:53:21.917: I/dalvikvm(807): Wrote stack traces to '/data/anr/traces.txt'
    08-03 10:53:22.087: D/AndroidRuntime(807): Shutting down VM
    08-03 10:53:22.087: W/dalvikvm(807): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    08-03 10:53:22.237: E/AndroidRuntime(807): FATAL EXCEPTION: main
    08-03 10:53:22.237: E/AndroidRuntime(807): java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
    08-03 10:53:22.237: E/AndroidRuntime(807):  at com.eConnect.Restaurant.TicketActivity$EfficientAdapter.getView(TicketActivity.java:91)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.AbsListView.obtainView(AbsListView.java:2033)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.ListView.makeAndAddView(ListView.java:1772)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.ListView.fillDown(ListView.java:672)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.ListView.fillFromTop(ListView.java:732)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.ListView.layoutChildren(ListView.java:1625)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.AbsListView.onLayout(AbsListView.java:1863)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.view.View.layout(View.java:11278)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
       08-03 10:53:22.237: E/AndroidRuntime(807):   at android.view.View.layout(View.java:11278)
     08-03 10:53:22.237: E/AndroidRuntime(807):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.View.layout(View.java:11278)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.View.layout(View.java:11278)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
         08-03 10:53:22.237: E/AndroidRuntime(807):     at android.view.View.layout(View.java:11278)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.os.Handler.dispatchMessage(Handler.java:99)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at android.os.Looper.loop(Looper.java:137)
       08-03 10:53:22.237: E/AndroidRuntime(807):   at android.app.ActivityThread.main(ActivityThread.java:4424)
        08-03 10:53:22.237: E/AndroidRuntime(807):  at java.lang.reflect.Method.invokeNative(Native Method)
         08-03 10:53:22.237: E/AndroidRuntime(807):     at java.lang.reflect.Method.invoke(Method.java:511)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
      08-03 10:53:22.237: E/AndroidRuntime(807):    at dalvik.system.NativeStart.main(Native Method)
     08-03 10:53:22.358: I/dalvikvm(807): threadid=3: reacting to signal 3

Thanks in Advance;

  • 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-09T03:10:17+00:00Added an answer on June 9, 2026 at 3:10 am

    make sure, HomeActivity.select1.length, and GlobalClass.myval.size() and GlobalClass.myvals.size() are of same size.

    I am editing your answer, please make a note its just a workaround, coz to get a proper solution I need to understand these data sources well.

    public class TicketActivity extends Activity{
    TextView t1;
    TextView t2;
    ListView l1;
    TextView t6;
      public void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);
      setContentView(R.layout.ticket);
      t1=(TextView)findViewById(R.id.textView3);
      t2=(TextView)findViewById(R.id.textView5);
       l1=(ListView)findViewById(R.id.listView1);
    
         //Get the Table no Value From Edit Text
    
    
       Intent i1=getIntent();
       Bundle b=i1.getExtras();
        int num=b.getInt("Table No:");
        String pno=Integer.toString(num);
        t1.setText(pno);
    
            //Get The Guest Value From Edit Text
    
        Intent i2=getIntent();
        Bundle b1=i2.getExtras();
        int num1=b1.getInt("Guest:");
        String pno1=Integer.toString(num1);
        t2.setText(pno1);
    
    
    
        l1.setAdapter(new EfficientAdapter(TicketActivity.this));
    
       } 
       private static class EfficientAdapter extends BaseAdapter{
        private LayoutInflater mInflater;
    
    
    
        public EfficientAdapter(Context context){
            mInflater=LayoutInflater.from(context);
    
        // implementation of EfficientAdapter   
        }
        public int getCount() {
    
            return GlobalClass.myval.size()<GlobalClass.myvals.size()?GlobalClass.myval.size():GlobalClass.myvals.size();
    
        }
        public Object getItem(int position) {
    
            return position;
        }
        public long getItemId(int position) {
    
            return position ;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            String[] stockArr = new String[GlobalClass.myval.size()];
            stockArr = GlobalClass.myval.toArray(stockArr);
            String[] stockArr1=new String[GlobalClass.myvals.size()];
            stockArr1=GlobalClass.myvals.toArray(stockArr1);
        if(convertView==null){
                convertView=mInflater.inflate(R.layout.list_ticket, null);
                holder=new ViewHolder();
                holder.Text1=(TextView)          convertView.findViewById(R.id.textView1);
                holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
                holder.Text3=(TextView) convertView.findViewById(R.id.textView3);
                convertView.setTag(holder);
            }
            else{
                  holder=(ViewHolder)convertView.getTag();
                }
    
                holder.Text2.setText(stockArr[position]);
                holder.Text3.setText(stockArr1[position]);
                return convertView;
    
         }
    
        }
        static class ViewHolder{
            TextView Text1;
            TextView Text2;
            TextView Text3;
    
        }
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I should avoid using global variables in the first place due to
To avoid singletons and global variables I'd like to be able to pass parameters
Why should we avoid using class variables @@ in rails? Is there any security
I'd like avoid loop I have this : string s = AAAA,12,BBBB,34,CCCCC,56; With Linq,
I always try to avoid to return string literals, because I fear they aren't
To avoid the long class path issue in windows, i modified my build.xml like[1]
To avoid crashing anything I specify the version number for every gem in my
I'd like to avoid this scary messages when users install my application: I understand
I'd like to avoid doing any needless HTTP requests on my site to improve
I am trying to avoid C6011 warning because an abort function is calling exit().

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.