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

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

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

Querify Question: Largest Hub for Question Solutions and Expert Answers

Querify Question: Largest Hub for Question Solutions and Expert Answers Logo Querify Question: Largest Hub for Question Solutions and Expert Answers Logo

Querify Question: Largest Hub for Question Solutions and Expert Answers Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 351052

Querify Question: Largest Hub for Question Solutions and Expert Answers Latest Articles

admin
  • 159
adminEnlightened
Asked: June 27, 20242024-06-27T20:34:54+00:00 2024-06-27T20:34:54+00:00

android view extends class force close error

  • 159

I am working Drawing Application. I am Draw View Class Extends View for Drawing Below For Draw.java class:

package com.draw; import java.util.ArrayList; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path;  import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView;  public class DrawView extends View implements OnTouchListener {     private Canvas  mCanvas;     private Path    mPath;     private Paint       mPaint;        private ArrayList<Path> paths = new ArrayList<Path>();     private ArrayList<Path> undonePaths = new ArrayList<Path>();       private Bitmap im;     public DrawView(Context context)      {         super(context);         setFocusable(true);         setFocusableInTouchMode(true);               this.setOnTouchListener(this);         mPaint = new Paint();         mPaint.setAntiAlias(true);         mPaint.setDither(true);         mPaint.setColor(0xFFFFFFFF);         mPaint.setStyle(Paint.Style.STROKE);         mPaint.setStrokeJoin(Paint.Join.ROUND);         mPaint.setStrokeCap(Paint.Cap.ROUND);         mPaint.setStrokeWidth(6);         mCanvas = new Canvas();         mPath = new Path();         paths.add(mPath);          im=BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_launcher);       }                        @Override         protected void onSizeChanged(int w, int h, int oldw, int oldh) {             super.onSizeChanged(w, h, oldw, oldh);         }          @Override         protected void onDraw(Canvas canvas) {                          for (Path p : paths){                 canvas.drawPath(p, mPaint);             }         }          private float mX, mY;         private static final float TOUCH_TOLERANCE = 4;          private void touch_start(float x, float y) {             mPath.reset();             mPath.moveTo(x, y);             mX = x;             mY = y;         }         private void touch_move(float x, float y) {             float dx = Math.abs(x - mX);             float dy = Math.abs(y - mY);             if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {                 mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);                 mX = x;                 mY = y;             }         }         private void touch_up() {             mPath.lineTo(mX, mY);             // commit the path to our offscreen             mCanvas.drawPath(mPath, mPaint);             // kill this so we don't double draw                         mPath = new Path();             paths.add(mPath);         }          public void onClickUndo () {              if (paths.size()>0)              {                 undonePaths.add(paths.remove(paths.size()-1));                invalidate();              }             else             {              }              //toast the user          }          public void onClickRedo (){            if (undonePaths.size()>0)             {                 paths.add(undonePaths.remove(undonePaths.size()-1));                 invalidate();            }             else             {             }              //toast the user          }      @Override     public boolean onTouch(View arg0, MotionEvent event) {           float x = event.getX();           float y = event.getY();            switch (event.getAction()) {               case MotionEvent.ACTION_DOWN:                   touch_start(x, y);                   invalidate();                   break;               case MotionEvent.ACTION_MOVE:                   touch_move(x, y);                   invalidate();                   break;               case MotionEvent.ACTION_UP:                   touch_up();                   invalidate();                   break;           }           return true;     } } 

And I am mentioned my layout below :

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >       <RelativeLayout         android:id="@+id/relativeLayout1"         android:layout_width="fill_parent"         android:layout_height="fill_parent" >          <com.draw.DrawView             android:id="@+id/view1"             android:layout_width="fill_parent"             android:layout_height="400dp"              />          <Button             android:id="@+id/button1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignParentBottom="true"             android:layout_alignParentLeft="true"             android:text="Undo" />          <Button             android:id="@+id/button2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignParentBottom="true"             android:layout_centerHorizontal="true"             android:text="Redo" />      </RelativeLayout>    </LinearLayout> 

And My Activity Class Code Below:

package com.draw;  import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.Toast;  public class Draw extends Activity {     DrawView draw_view ;     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         //drawView = new DrawView(this);         setContentView(R.layout.main);         //drawView.requestFocus();         try         {          draw_view=(DrawView) findViewById(R.id.view1);         }         catch (Exception e) {             // TODO: handle exception             Toast.makeText(getApplicationContext(), e.toString(),4000).show();         }         Button btn_undo=(Button) findViewById(R.id.button1);         btn_undo.setOnClickListener(new OnClickListener() {              @Override             public void onClick(View v) {                 // TODO Auto-generated method stub                 draw_view.onClickUndo();             }         });     }  } 

Xml Load Error Occured in Logcat

05-15 16:27:01.407: E/AndroidRuntime(1064): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.draw/com.draw.Draw}: android.view.InflateException: Binary XML file line #13: Error inflating class com.draw.DrawView 

What's wrong in my code?

Related Posts
  • Related Link: android the button view has never been used in the function
android
  • 0 0 Answers
  • 1k Views
  • 0 Followers
  • 1k
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 1mil
  • Answer 1
  • Best Answers 0
  • Users 40k
  • Popular
  • Answers
  • admin

    vba code excel range not pasting to outlook properly

    • 1 Answer
  • MilaBrext

    Заказать Хавал - только у нас вы найдете цены ниже ...

    • 0 Answers
  • admin

    Creating a Regex to Match the First N Characters of ...

    • 0 Answers
  • Reda
    Reda added an answer Convert Range to Text February 27, 2025 at 8:30 pm

Top Members

admin

admin

  • 1mil Questions
  • 855 Points
Enlightened
Reda

Reda

  • 0 Questions
  • 22 Points
Begginer
Aria Carter

Aria Carter

  • 0 Questions
  • 21 Points
Begginer

Trending Tags

android azuredevops azurepipelines c database debugging decimal docker html ios java javascript jquery php python reactjs regex rubyonrails sql vlc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question: Largest Hub for Question Solutions and Expert Answers

Querify Question: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

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.