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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:55:42+00:00 2026-06-13T12:55:42+00:00

Iam beginner in android game development and i’m currently having some trouble on drawing

  • 0

Iam beginner in android game development and i’m currently having some trouble on drawing pixels on the screen using bitmap and canvas.

Here is my code:

package com.example.arkanoid;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;
import android.graphics.*;

public class MainActivity extends Activity {
    Bitmap  bitmap;
    Canvas canvas;
    int lastx=0, lasty=0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bitmap = Bitmap.createBitmap(400,400,Bitmap.Config.ARGB_8888);
        canvas = new Canvas(bitmap);
        bitmap.prepareToDraw();
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void drawPixel(int x, int y) {
        if(bitmap.isMutable()) {
            bitmap.setPixel(x,y,Color.rgb(100,100,100));
        }
        canvas.drawBitmap(bitmap,0,0,null);
    }

    public boolean onTouchEvent(MotionEvent event) {
        int x = (int)event.getX();
        int y = (int)event.getY();
        TextView texto = (TextView)findViewById(R.id.textView1); 
        texto.setText("X: "+x+", Y: "+y);
        if(lastx !=x || lasty !=y){
            lastx=x;
            lasty=y;
            drawPixel(x,y);
        }
    return false;
    }
}

When the function drawPixel(int x, int y) is called multiple times the application stops running:

Error

And no pixels are drawn, so what is the error here? thanks for your time.

I forgot the LOG from LogCat, sorry:

http://txtup.co/eISoF

  • 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-13T12:55:43+00:00Added an answer on June 13, 2026 at 12:55 pm

    according for the logcat you uploaded, you need to check if x & y are between the bitmap size.

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

Sidebar

Related Questions

I am beginner in android application development. If i am using n number of
I am a beginner in Android game development, while searching i found Rokon, a
i am beginner in Android app development i am working on a app which
I am a beginner in Android. I am developing one animated game in Activity(not
I am a beginner in Android. I created an activity for the first screen,
I am a beginner of Android apps and am using Eclipse. I have found
i am beginner in android development. How to send images among the different android
(I am a beginner at android, so be nice!) I am making a game
I am beginner in android.I faced some problems durinng sdk locating.How to locate android
I am beginner in the android development, can any one tell me how to

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.