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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:28:33+00:00 2026-05-31T12:28:33+00:00

Here’s my code: public class RT extends Activity implements OnTouchListener{ DrawPanel dp; private ArrayList<Path>

  • 0

Here’s my code:

public class RT extends Activity implements OnTouchListener{

    DrawPanel dp;
    private ArrayList<Path> pointsToDraw = new ArrayList<Path>();
    private Paint mPaint;
    Path path;
    private int strokeNumber = 0;
    double strokeLength = 0.0;
    PathMeasure p;
    double s1 = 0.0,s2 = 0.0 ,s3 = 0.0,s4 = 0.0;
    String st1,st2,st3,st4;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        dp = new DrawPanel(this);
        dp.setOnTouchListener(this);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.WHITE);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(30);

        final TextView tv1 = new TextView(this);  
        tv1.setText("Generated Text Goes Here");  
        tv1.setTextSize(30);  
        tv1.setTextColor(Color.WHITE);
        tv1.setGravity(Gravity.BOTTOM);
        tv1.setId(R.id.TGText);


        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


        Button b1 = new Button(this);  
        b1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
        b1.setTextSize(20);  
        b1.setText("Generate");  
        b1.setTextColor(Color.WHITE);
        b1.setId(R.id.TGButton);
        b1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                p = new PathMeasure(path,false);
                strokeLength = p.getLength();
                tv1.setText("Length of stroke: " + Double.toString(strokeLength) + "stroke number = " + strokeNumber);
                if(strokeNumber == 1){
                    s1 = strokeLength;

                    if(s1 < 150.0)
                        st1 = "S";
                    if(s1 > 150.0 && s1 < 250.0)
                        st1 = "M";
                    if(s1 > 250.0 && s1 < 350.0)
                        st1 = "L";
                    if(s1 > 350.0)
                        st1 = "VL";

                }

                if(strokeNumber == 2){
                    s2 = strokeLength;

                    if(s2 < 150.0)
                        st2 = "S";
                    if(s2 > 150.0 && s2 < 250.0)
                        st2 = "M";
                    if(s2 > 250.0 && s2 < 350.0)
                        st2 = "L";
                    if(s2 > 350.0)
                        st2 = "VL";

                }


                if(strokeNumber == 3){
                    s3 = strokeLength;

                    if(s3< 150.0)
                        st3 = "S";
                    if(s3 > 150.0 && s3 < 250.0)
                        st3 = "M";
                    if(s3 > 250.0 && s3 < 350.0)
                        st3 = "L";
                    if(s3 > 350.0)
                        st3 = "VL";

                }

                if(strokeNumber == 4){
                    s4 = strokeLength;

                    if(s4 < 150.0)
                        st4 = "S";
                    if(s4 > 150.0 && s4 < 250.0)
                        st4 = "M";
                    if(s4 > 250.0 && s4 < 350.0)
                        st4 = "L";
                    if(s4 > 350.0)
                        st4 = "VL";

                }

            }
        });

        ll.addView(b1);

        Button b2 = new Button(this);  
        b2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
        b2.setTextSize(20);  
        b2.setText("Back");  
        b2.setTextColor(Color.WHITE);
        b2.setId(R.id.TBButton);
        b2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
            }
        });

        ll.addView(b2);

        final AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Match to?");
        alert.setMessage("Match this to which alphabet?");

        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
          String value = input.getText().toString();
          //insertValue(value,st1,st2,st3,st4);
          }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
          }
        });



        Button b3 = new Button(this);  
        b3.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
        b3.setTextSize(20);  
        b3.setText("Store");  
        b3.setTextColor(Color.WHITE);
        b3.setId(R.id.TSButton);
        b3.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                    alert.show();
                    dp.clearCanvas();   
                    tv1.setText(st1 + " " + st2 + " " + st3 + " " + st4);
                    s1 = 0.0f;
                    s2 = 0.0f;
                    s3 = 0.0f;
                    s4 = 0.0f;
                } 
        });

        ll.addView(b3);

        Button b4 = new Button(this);  
        b4.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
        b4.setTextSize(20);  
        b4.setText("Clear");  
        b4.setTextColor(Color.WHITE);
        b4.setId(R.id.TCButton);
        b4.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dp.clearCanvas();
                tv1.setText("");
            }
        });

        ll.addView(b4);




        FrameLayout fl = new FrameLayout(this);  
        fl.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
        fl.addView(dp);  
        fl.addView(tv1);  
        fl.addView(ll);
        setContentView(fl);  

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        dp.pause();
    }

        @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        dp.resume();
    }


    private void insertValue(String alphabet, String stroke1,String stroke2,String stroke3,String stroke4) {
            DatabaseHelper databaseHelper = new DatabaseHelper(this);
            SQLiteDatabase db = databaseHelper.getWritableDatabase();

            ContentValues cv = new ContentValues();
            cv.put(DatabaseHelper.Alpha, alphabet);
            cv.put(DatabaseHelper.s1, stroke1);
            cv.put(DatabaseHelper.s2, stroke2);
            cv.put(DatabaseHelper.s3, stroke3);
            cv.put(DatabaseHelper.s4, stroke4);

            db.insert("capitals", null, cv);
            db.close();
        }





    public class DrawPanel extends SurfaceView implements Runnable{

        Thread t = null;
        SurfaceHolder holder;
        boolean isItOk = false ;

        public DrawPanel(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
            holder = getHolder();
        }

        @Override
        public void run() {
            // TODO Auto-generated method stub
            while( isItOk == true){

                if(!holder.getSurface().isValid()){
                    continue;
                }

                Canvas c = holder.lockCanvas();
                c.drawARGB(255, 0, 0, 0);
                onDraw(c);
                holder.unlockCanvasAndPost(c);
            }
        }

        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            synchronized(pointsToDraw)
            {
                for (Path path : pointsToDraw) {
                    canvas.drawPath(path, mPaint);
            }
            }
        }

        public void pause(){
            isItOk = false;
            while(true){
                try{
                    t.join();
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                break;
            }
            t = null;
        }

        public void resume(){
            isItOk = true;  
            t = new Thread(this);
            t.start();

        }

        public void clearCanvas(){
            Canvas c = holder.lockCanvas();
            c.drawColor(Color.BLACK);
            pointsToDraw.clear();
            holder.unlockCanvasAndPost(c);
            strokeNumber = 0;
        }



    }


    @Override
    public boolean onTouch(View v, MotionEvent me) {
        synchronized(pointsToDraw)
        {
        // TODO Auto-generated method stub
        if(me.getAction() == MotionEvent.ACTION_DOWN){
            path = new Path();
            path.moveTo(me.getX(), me.getY());
            //path.lineTo(me.getX(), me.getY());
            pointsToDraw.add(path);
            strokeNumber++;
        }else if(me.getAction() == MotionEvent.ACTION_MOVE){
            path.lineTo(me.getX(), me.getY());
        }else if(me.getAction() == MotionEvent.ACTION_UP){
            //path.lineTo(me.getX(), me.getY());
        }
        }
        return true;

    }

    @Override
    public void onBackPressed() {
       return;
    }


}

Here’s the log content:

03-19 19:48:19.254: E/AndroidRuntime(1185): FATAL EXCEPTION: main
03-19 19:48:19.254: E/AndroidRuntime(1185): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.view.ViewGroup.addViewInner(ViewGroup.java:3337)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.view.ViewGroup.addView(ViewGroup.java:3208)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.view.ViewGroup.addView(ViewGroup.java:3188)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at com.android.internal.app.AlertController.setupView(AlertController.java:401)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at com.android.internal.app.AlertController.installContent(AlertController.java:241)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.app.AlertDialog.onCreate(AlertDialog.java:336)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.app.Dialog.dispatchOnCreate(Dialog.java:353)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.app.Dialog.show(Dialog.java:257)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at learn.myandroidapp.hr.HandwritingRecognitionTrainer$5.onClick(HandwritingRecognitionTrainer.java:200)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.view.View.performClick(View.java:3511)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.view.View$PerformClick.run(View.java:14105)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.os.Handler.handleCallback(Handler.java:605)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.os.Looper.loop(Looper.java:137)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at android.app.ActivityThread.main(ActivityThread.java:4424)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at java.lang.reflect.Method.invokeNative(Native Method)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at java.lang.reflect.Method.invoke(Method.java:511)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-19 19:48:19.254: E/AndroidRuntime(1185):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-19 19:48:19.254: E/AndroidRuntime(1185):     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-31T12:28:34+00:00Added an answer on May 31, 2026 at 12:28 pm

    Found the issue. Thanks to Tim. Here are the corrections:

      final AlertDialog.Builder alert = new AlertDialog.Builder(this);
            final AlertDialog alertd = alert.create();
    
            alert.setTitle("Match to?");
            alert.setMessage("Match this to which alphabet?");
    
            // Set an EditText view to get user input 
            final EditText input = new EditText(this);
            alert.setView(input);
    
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              String value = input.getText().toString();
              //insertValue(value,st1,st2,st3,st4);
              }
            });
    
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
                  dialog.cancel();
                  alertd.dismiss();
              }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here is my code, which takes two version identifiers in the form 1, 5,
Here is an example: I write html code inside of textarea, then I swap
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is my code sample, let me know if it can be further improved?
Here is my code (Say we have a single button on the page that
here are 2 screen shots when i try to debug my code in visual
Here a simple question : What do you think of code which use try
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY

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.