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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:40:16+00:00 2026-06-14T05:40:16+00:00

Description: I created View where i had drawn rectangle using canvas and also implemented

  • 0

Description:

I created View where i had drawn rectangle using canvas and also implemented On Touch Event in that View.

I want that touch to launch new activity.

Problem:

Now the problem is whenever i touch that rectangle “Force Close” error is popping up.

Here is the PickCardView.java

  public class PickCardView extends View
    {   
    private Paint mCanvasPaint;

    private Rect mScreenSize = new Rect();

    private Rect mCardSize = new Rect();
    private int mCardCap;

    private Card MCards;

    public PickCardView(Context context) 
    {
        super(context);

        mCanvasPaint = new Paint();
        mCanvasPaint.setColor(0xFF228B22); // Green background
        mCanvasPaint.setAntiAlias(false);
        mCanvasPaint.setFilterBitmap(false);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) 
    {
        super.onSizeChanged(w, h, oldw, oldh);

        // Store current screen size
        mScreenSize.set(0, 0, w, h);

        // Calculate card and decks sizes and positions
        int cw = w / 11;
        mCardSize.set(0, 0, cw, (int) (cw * 1.5));
        Log.v("card size", mCardSize.toString());

        int freeSize = w - cw * 7; //117
        mCardCap = freeSize / (6 + 4 * 2);//5

        int cy = (int) (mScreenSize.height() * 0.35);

        //MIDDLE CARD HOLDER
        MCards = new Card(Card.CardType.PickDeck, mCardCap * 2 + mCardSize.width()*4 - 15, cy - 20, mCardSize.width()+60, mCardSize.height()+60);
    }

    @Override
    public void onDraw(Canvas canvas) 
    {
        mCanvasPaint.setStyle(Style.FILL);
        canvas.drawRect(mScreenSize, mCanvasPaint);

        MCards.doDraw(canvas);     
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        int action = event.getAction();

        if (action == MotionEvent.ACTION_DOWN) 
        {
            int x = (int) event.getX();
            int y = (int) event.getY();

            Card card = getCardUnderTouch(x, y);

            if(card != null)
            {
                Intent i = new Intent(null, BuildWord.class);  
                startActivity(i);
            }
        }

        return true;
    }

    private void startActivity(Intent i) 
    {
        //Intent i1 = new Intent(null, BuildWord.class);        
    }

    private Card getCardUnderTouch(int x, int y) 
    {
        Card ret = null;

        if (MCards.isUnderTouch(x, y)) 
        {
            return MCards;
        }

        return ret;
    }
}

This is error shown in logcat when i touch that rectangle:

11-13 21:07:12.037: E/InputEventReceiver(712): Exception dispatching input event.
11-13 21:07:12.037: E/MessageQueue-JNI(712): Exception in MessageQueue callback: handleReceiveCallback
11-13 21:07:12.138: E/MessageQueue-JNI(712): java.lang.NullPointerException
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.content.ComponentName.<init>(ComponentName.java:75)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.content.Intent.<init>(Intent.java:3301)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at apk.gameshufflewords.PickCardView.onTouchEvent(PickCardView.java:79)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.View.dispatchTouchEvent(View.java:7127)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1877)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1877)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1877)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.View.dispatchPointerEvent(View.java:7307)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.os.MessageQueue.nativePollOnce(Native Method)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.os.MessageQueue.next(MessageQueue.java:125)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.os.Looper.loop(Looper.java:124)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at android.app.ActivityThread.main(ActivityThread.java:4745)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at java.lang.reflect.Method.invokeNative(Native Method)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at java.lang.reflect.Method.invoke(Method.java:511)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 21:07:12.138: E/MessageQueue-JNI(712):    at dalvik.system.NativeStart.main(Native Method)
11-13 21:07:12.167: D/AndroidRuntime(712): Shutting down VM
11-13 21:07:12.167: W/dalvikvm(712): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-13 21:07:12.267: E/AndroidRuntime(712): FATAL EXCEPTION: main
11-13 21:07:12.267: E/AndroidRuntime(712): java.lang.NullPointerException
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.content.ComponentName.<init>(ComponentName.java:75)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.content.Intent.<init>(Intent.java:3301)
11-13 21:07:12.267: E/AndroidRuntime(712):  at apk.gameshufflewords.PickCardView.onTouchEvent(PickCardView.java:79)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.View.dispatchTouchEvent(View.java:7127)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1877)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1877)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1877)
11-13 21:07:12.267: E/AndroidRuntime(712):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
11-13 21:07:12.267: E/AndroidRuntime(712):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
11-13 21:07:12.267: E/AndroidRuntime(712):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.View.dispatchPointerEvent(View.java:7307)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.os.MessageQueue.nativePollOnce(Native Method)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.os.MessageQueue.next(MessageQueue.java:125)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.os.Looper.loop(Looper.java:124)
11-13 21:07:12.267: E/AndroidRuntime(712):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-13 21:07:12.267: E/AndroidRuntime(712):  at java.lang.reflect.Method.invokeNative(Native Method)
11-13 21:07:12.267: E/AndroidRuntime(712):  at java.lang.reflect.Method.invoke(Method.java:511)
11-13 21:07:12.267: E/AndroidRuntime(712):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-13 21:07:12.267: E/AndroidRuntime(712):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 21:07:12.267: E/AndroidRuntime(712):  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-06-14T05:40:17+00:00Added an answer on June 14, 2026 at 5:40 am

    Change onTouchEvent to

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
    int action = event.getAction();
    
    if (action == MotionEvent.ACTION_DOWN) 
    {
        int x = (int) event.getX();
        int y = (int) event.getY();
    
        Card card = getCardUnderTouch(x, y);
    
        if(card != null)
        {
            Context context = getContext();
            Intent i = new Intent(context, BuildWord.class);  
            context.startActivity(i);
        }
    }
    
    return true;
    }
    

    remove your startActivity method as well

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

Sidebar

Related Questions

Using storyboard ,I created a project. Inside viewDidLoad ,I did : NSLog(@"%@",self.view.description); I got
I have a simple form created using Ajax.BeginForm : <% using (Ajax.BeginForm(Update, Description, new
I have a zip file that is created using drag and drop on a
I have created and XML parser that acquires the data in the description tag.
I have created a custom view that contains a UIPickerView and a UITableViewCell to
I've created a simple Project model with four attributes: Project name:string description:text complete:boolean user_id:integer
I have created a table with the following columns: ObservationId, FirstCreatedDate, description, ... ...
Hi I have created a setDecorator() which is something like this: $timeSu->setDecorators(array('ViewHelper', 'Description', 'Errors',
Here is a test description, testing the Create New Widget use-case. Confirm that you
this table i want to create job_id dynamic Jobs Title text Job Description text

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.