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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:47:45+00:00 2026-06-01T08:47:45+00:00

For Andriod I have this code: public Tank(int color) { bounds = new RectF();

  • 0

For Andriod I have this code:

public Tank(int color) {
    bounds = new RectF();
    paint = new Paint();
    paint.setColor(color);
}

public void draw(Canvas canvas) {
    bounds.set(x - radius, y - radius, x + radius, y + radius);
    canvas.drawRect(bounds, paint);
}

where I am drawing a Rect, but now I want to draw a Bitmap instead of a Rect, but

bitTank = BitmapFactory.decodeRescource(getRescource(),R.drawable.ic_launcher);

or

bitTank = BitmapFactory.decodeFile("C:\Users\...\res\drawable-hdpi\ic_launcher.png");

(both) in combination with

canvas.drawBitmap(bitTank, matrix, null);

is not working.

The first does not know getRescource() and with the second one it doesn’t work anymore. How can I realize that? (The Code is in the class Tank and another class calls the draw function).

  • 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-01T08:47:46+00:00Added an answer on June 1, 2026 at 8:47 am

    The second version simply cannot work, because you are trying to access a file on your PC from the inside Android app. Android doesn’t know anything about your local PC.

    With the first code, you need an instance of Context to access resources. You can pass a context into your constructor and then use it:

    class Tank {
        Context context;
        ...
    
        public Tank(int color, Context ctx) {
            context = ctx;
    
            bounds = new RectF();
            paint = new Paint();
            paint.setColor(color);
        }
    
        public void draw(Canvas canvas) {
            ...
            bitTank = BitmapFactory.decodeRescource(context.getRescources(),R.drawable.ic_launcher);
            ...
        }
    }
    

    While this is not the only way to achieve what you’re after, it should get you started.

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

Sidebar

Related Questions

I have this code on my Android phone. URI uri = new URI(url); HttpPost
I have try this code on DatabaseHelper.java Line Number 34 public DatabaseHelper(Context context) throws
I'm a beginner in Android. Here I have this code: public class GPS extends
I have this code copied from Android developers website: public class ExampleActivity extends Activity
I have this code to show an AlertDialog when taping on a marker: public
i have this code package com.tct.soundTouch; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.MotionEvent;
I have this code for Jaro-Winkler algorithm taken from this website. I need to
I have this Code to Capture a image and Display it back in ListView
I have this code: package com.problemio; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View;
why SqlLite query in android produce Nullpointer exception I am using this code public

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.