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

  • Home
  • SEARCH
  • 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 7182189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:43:01+00:00 2026-05-28T17:43:01+00:00

Let me start off with I’m mostly new to writing Java, so I would

  • 0

Let me start off with I’m mostly new to writing Java, so I would love for a complete explanation. Not just a spew of code, but something that gives some in site to why and where it should be

I’m currently attempting to write an Application, how ever I’m have some trouble with the Canvas and drawing the bitmap I would like onto it. This is my code to draw the image:

Canvas canvas = null;
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.image);
canvas.drawBitmap(image, 10, 800, null);

This method (expectantly) throws a Null Pointer Exception. However, Defining “canvas” as null is the only option Eclipse gives me. When attempting to define it as

Canvas canvas = new Canvas();

Android simply refuses to draw the bitmap. I’m sure my image is located at res/drawable/image
If it helps, the image is saved as “image.png”

How would I make Android display/display my image/bitmap at the specific location I have asked it to draw the image (10×800)?

  • 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-28T17:43:02+00:00Added an answer on May 28, 2026 at 5:43 pm

    Writing nonsense that solves a compiler error doesn’t change the fact that it’s nonsense! 🙂

    You have to get a reference to a Canvas object another way. You might want to be more specific about what you are exactly trying to do, so that we can suggest how you should go about it. (Ex. are you attempting to just display an image along with some other Views? Are you trying to create a custom View? You might just want to consider using an ImageView)

    Edit:

    You should read up about Android architecture at developer.android.com . If you are simply trying to show an image, there might not be a reason to use the canvas directly. Nonetheless, you can draw within a custom View by extending the View class

    class myView extends View{
    
        Bitmap bm;
    
        loadBitmap()
        {
            bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
        }
    
        @Override
        public void draw(Canvas c)
        {
           c.drawBitmap(bm, XCORD, YCORD, null);
        }
    }
    

    if you don’t need a custom view, just use the ImageView class

    class MyActivty extends Activity{
       @Override
       public void onCreate(Bundle b)
       {
           super.onCreate(b);
           ImageView iv = new ImageView(this);
           iv.setImageResource(R.drawable.pic);
           setContentView(iv);
       }
    }
    

    Warning: I wrote those method calls off of the top of my head, they might be slightly off.

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

Sidebar

Related Questions

Let me start off by saying, I'm not new to programming but am very
First off, let me start off that I am not a .net developer. The
First off, let me start by saying that I am totally new to working
First let me start off by saying I do not believe I am leaking,
Let me start off by saying I had one DLL loading in just fine.
Let me start off by saying that I am completely new with WPF (this
Let me start off by saying that I am very new to WPF and
Let me start off by saying Im VERY new to iphone development, but Im
Preface Let me start off by saying that I'm a relatively new programmer and
Let me start off by apologizing for not giving a code snippet. The project

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.