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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:42:43+00:00 2026-05-27T06:42:43+00:00

In my application i am using A to Z alphabets as images and getting

  • 0

Emulator image

In my application i am using A to Z alphabets as images and getting the dragged and dropped.I am saving these images in a array.And the problem arrises when i click back button or clear button in which back takes the activity to previous menu and clear redirects the activity again to same page so ultimately alphabet images takes its initial position.
Actually when i press clear and back button its overriding the images onto the same array and hence since the array size is only 26 .I am getting ArrayIndexOutOfBoundException.Please assist me how do i refresh or remove the array images before its the activity is navigated to another screen so that the next time this view is opened array data is initialized afresh.

I am providing both class One where i had declared and defined the array and another class where i am accessing the above class view and has button to navigate to another activities onClick.Please assist me.Thanx.

DrawView Class:

 public class DrawView extends View {
   public ColorBall[] colorballs = new ColorBall[26]; // array that holds the balls
   public int balID = 0; // variable to know what ball is being dragged

    public DrawView(Context context) {
        super(context);
        setFocusable(true); //necessary for getting the touch events

        // setting the start point for the balls
        Point point1 = new Point();
        point1.x = 50;
        point1.y = 0;
        Point point2 = new Point();
        point2.x = 150;
        point2.y = 0;
        Point point3 = new Point();
        point3.x = 250;
        point3.y = 0;
        Point point4 = new Point();
        point4.x = 350;
        point4.y = 0;
        Point point5 = new Point();
        point5.x = 400;
        point5.y = 0;
        Point point6 = new Point();
        point6.x = 50;
        point6.y = 50; 
        Point point7 = new Point();
        point7.x = 150;
        point7.y =50; 
        Point point8 = new Point();
        point8.x = 250;
        point8.y = 50; 
        Point point9 = new Point();
        point9.x = 350;
        point9.y = 50;
        Point point10 = new Point();
        point10.x = 400;
        point10.y = 50;
        Point point11 = new Point();
        point11.x = 50;
        point11.y = 100; 
        Point point12 = new Point();
        point12.x = 150;
        point12.y = 100;
        Point point13 = new Point();
        point13.x = 250;
        point13.y = 100;
        Point point14 = new Point();
        point14.x = 350;
        point14.y = 100;
        Point point15 = new Point();
        point15.x = 400;
        point15.y = 100;
        Point point16 = new Point();
        point16.x = 50;
        point16.y = 150;
        Point point17 = new Point();
        point17.x = 150;
        point17.y = 150;
        Point point18 = new Point();
        point18.x = 250;
        point18.y = 150;
        Point point19 = new Point();
        point19.x = 350;
        point19.y = 150;
        Point point20 = new Point();
        point20.x = 400;
        point20.y = 150;
        Point point21 = new Point();
        point21.x = 50;
        point21.y = 200;
        Point point22 = new Point();
        point22.x = 150;
        point22.y = 200;
        Point point23 = new Point();
        point23.x = 250;
        point23.y = 200;
        Point point24 = new Point();
        point24.x = 350;
        point24.y = 200;
        Point point25 = new Point();
        point25.x = 400;
        point25.y = 200;
        Point point26 = new Point();
        point26.x = 200;
        point26.y = 250; 
        // declare each ball with the ColorBall class
        colorballs[0] = new ColorBall(context,R.drawable.e, point1);
        colorballs[1] = new ColorBall(context,R.drawable.l, point2);
        colorballs[2] = new ColorBall(context,R.drawable.z, point3);
        colorballs[3] = new ColorBall(context,R.drawable.h, point4);
        colorballs[4] = new ColorBall(context,R.drawable.a, point5);
        colorballs[5] = new ColorBall(context,R.drawable.c, point6);
        colorballs[6] = new ColorBall(context,R.drawable.y, point7);
        colorballs[7] = new ColorBall(context,R.drawable.s, point8);
        colorballs[8] = new ColorBall(context,R.drawable.b2, point9);
        colorballs[9] = new ColorBall(context,R.drawable.o, point10);
        colorballs[10] = new ColorBall(context,R.drawable.n, point11);
        colorballs[11] = new ColorBall(context,R.drawable.v, point12);
        colorballs[12] = new ColorBall(context,R.drawable.i, point13);
        colorballs[13] = new ColorBall(context,R.drawable.x, point14);
        colorballs[14] = new ColorBall(context,R.drawable.f, point15);
        colorballs[15] = new ColorBall(context,R.drawable.j, point16);
        colorballs[16] = new ColorBall(context,R.drawable.t, point17);
        colorballs[17] = new ColorBall(context,R.drawable.q, point18);
        colorballs[18] = new ColorBall(context,R.drawable.w, point19);
        colorballs[19] = new ColorBall(context,R.drawable.u, point20);
        colorballs[20] = new ColorBall(context,R.drawable.k, point21);
        colorballs[21] = new ColorBall(context,R.drawable.r, point22);
        colorballs[22] = new ColorBall(context,R.drawable.p, point23);
        colorballs[23] = new ColorBall(context,R.drawable.d, point24);
        colorballs[24] = new ColorBall(context,R.drawable.m, point25);
        colorballs[25] = new ColorBall(context,R.drawable.g, point26);

    }

    // the method that draws the balls
    @Override protected void onDraw(Canvas canvas) {
        //canvas.drawColor(0xFFCCCCCC);     //if you want another background color       

        //draw the balls on the canvas
        for (ColorBall ball : colorballs) {
            canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), null);
          }

    }

    // events when touching the screen
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction(); 

        int X = (int)event.getX(); 
        int Y = (int)event.getY(); 

        switch (eventaction ) { 

        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
            balID = 0;
            for (ColorBall ball : colorballs) {
                // check if inside the bounds of the ball (circle)
                // get the center for the ball
                int centerX = ball.getX() + 25;
                int centerY = ball.getY() + 25;

                // calculate the radius from the touch to the center of the ball
                double radCircle  = Math.sqrt( (double) (((centerX-X)*(centerX-X)) + (centerY-Y)*(centerY-Y)));

                // if the radius is smaller then 23 (radius of a ball is 22), then it must be on the ball
                if (radCircle < 23){
                    balID = ball.getID();
                    break;
                }

                // check all the bounds of the ball (square)
                //if (X > ball.getX() && X < ball.getX()+50 && Y > ball.getY() && Y < ball.getY()+50){
                //  balID = ball.getID();
                //  break;
                //}
              }

             break; 


        case MotionEvent.ACTION_MOVE:   // touch drag with the ball
            // move the balls the same as the finger
            if (balID > 0) {
                colorballs[balID-1].setX(X-25);
                colorballs[balID-1].setY(Y-25);
            }

            break; 

        case MotionEvent.ACTION_UP: 
            // touch drop - just do things here after dropping

             break; 
        } 
        // redraw the canvas
        invalidate(); 
        return true; 

    }

}

Class Quiz1:

public class Quiz1 extends Activity{
    LinearLayout lLayout;
    TextView tView;
    DrawView d;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.e);
       ImageView v=(ImageView)findViewById(R.id.imageView1);
        v.setScaleType(ImageView.ScaleType.FIT_XY);
        ImageView v1=(ImageView)findViewById(R.id.imageView2);
        v1.setAlpha(60);

        ImageButton i3=(ImageButton)findViewById(R.id.imageButton3);
        i3.setOnClickListener(new OnClickListener(){

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Toast.makeText(getApplicationContext(), "'Home.'", Toast.LENGTH_SHORT).show();
Intent i=new Intent(Quiz1.this,LiamaLearningActivity.class);
startActivity(i);
            }
});
        ImageButton i2=(ImageButton)findViewById(R.id.imageButton2);
           i2.setOnClickListener(new OnClickListener(){

                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    Toast.makeText(getApplicationContext(), "'Cleared.'", Toast.LENGTH_SHORT).show();
    Intent i=new Intent(Quiz1.this,Quiz1.class);
    startActivity(i);
                }});

           ImageButton i1=(ImageButton)findViewById(R.id.imageButton1);
           i1.setOnClickListener(new OnClickListener(){

                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    Toast.makeText(getApplicationContext(), "'Sample Quizzes.'", Toast.LENGTH_SHORT).show();
    Intent i=new Intent(Quiz1.this,Quiz.class);
    startActivity(i);
                }});
        lLayout = new LinearLayout(this);
        lLayout.setOrientation(LinearLayout.VERTICAL);
        //-1(LayoutParams.MATCH_PARENT) is fill_parent or match_parent since API level 8
        //-2(LayoutParams.WRAP_CONTENT) is wrap_content
        lLayout.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, 
LayoutParams.MATCH_PARENT));
       /* tView = new TextView(this);
        tView.setText("Hello, This is a view created programmatically! " +
                  "You CANNOT change me that easily :-)");
        tView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, 
LayoutParams.WRAP_CONTENT));
        lLayout.addView(tView);*/
        d=new DrawView(this);
        d.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT, 700));
        lLayout.addView(d);
        AbsoluteLayout abs=(AbsoluteLayout)findViewById(R.id.a1);
        abs.addView(lLayout);
        //setContentView(lLayout);

    super.onDestroy();
    }
}

Logcat:

12-06 16:29:45.564: E/AndroidRuntime(278): java.lang.ArrayIndexOutOfBoundsException
12-06 16:29:45.564: E/AndroidRuntime(278):  at com.avigma.learning.DrawView.onTouchEvent(DrawView.java:176)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.View.dispatchTouchEvent(View.java:3766)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-06 16:29:45.564: E/AndroidRuntime(278):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
12-06 16:29:45.564: E/AndroidRuntime(278):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
12-06 16:29:45.564: E/AndroidRuntime(278):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.os.Looper.loop(Looper.java:123)
12-06 16:29:45.564: E/AndroidRuntime(278):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-06 16:29:45.564: E/AndroidRuntime(278):  at java.lang.reflect.Method.invokeNative(Native Method)
12-06 16:29:45.564: E/AndroidRuntime(278):  at java.lang.reflect.Method.invoke(Method.java:521)
12-06 16:29:45.564: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-06 16:29:45.564: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-06 16:29:45.564: E/AndroidRuntime(278):  at dalvik.system.NativeStart.main(Native Method)
  • 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-27T06:42:44+00:00Added an answer on May 27, 2026 at 6:42 am

    on click time on back button just call the finish() method if you want the start activity as new and do nothing it will finish the current activity and go back to the previous activity that was your menu

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

Sidebar

Related Questions

I am developing an application using TabHost. I am using android default back button
I'm building an application using gevent. My app is getting rather big now as
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I wrote an application using ASP.NET MVC, in this application I have an Index
I have a java-application using JDBC for database interaction. I want to do a
I deployed an application using this method and it worked very good. However, there
I'm building an application using the Supervising Controller pattern (Model View Presenter) and I
I'm using CakePHP to build an application using the MVC Pattern, but my question
We had an application using axis2 1.0. We recently migrated to axis2 1.4. After
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it

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.