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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:00:52+00:00 2026-06-18T22:00:52+00:00

How do I move an image in eclipse (that is already in the drawables

  • 0

How do I move an image in eclipse (that is already in the drawables file) to a specific spot on the screen?
this is the code I tried, don’t think its even close…

How does this look?

SurfaceHolder surfaceHolder;
SurfaceView surface = new SurfaceView(this);

Rect rect = new Rect(0,0,100,100);

This is in onCreate

    LinearLayout layout = (LinearLayout) findViewById(R.layout.activity_test2);
    surfaceHolder = surface.getHolder();
    layout.addView(surface);

(public view is in my main activity)

 public void onDraw(Canvas canvas) {

    canvas = surfaceHolder.lockCanvas();

    Bitmap image1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    canvas.drawBitmap(image1, null, rect, null);

    surfaceHolder.unlockCanvasAndPost(canvas);
}

LOGCAT

02-15 01:42:16.824: W/Trace(2782): Unexpected value from nativeGetEnabledTags: 0
02-15 01:42:16.824: W/Trace(2782): Unexpected value from nativeGetEnabledTags: 0
02-15 01:42:49.993: W/Trace(2782): Unexpected value from nativeGetEnabledTags: 0
02-15 01:43:03.026: W/Trace(2992): Unexpected value from nativeGetEnabledTags: 0
02-15 01:43:03.026: W/Trace(2992): Unexpected value from nativeGetEnabledTags: 0
02-15 01:43:03.026: W/Trace(2992): Unexpected value from nativeGetEnabledTags: 0
02-15 01:43:03.474: W/Trace(2992): Unexpected value from nativeGetEnabledTags: 0
02-15 01:43:03.505: W/Trace(2992): Unexpected value from nativeGetEnabledTags: 0
02-15 01:43:03.544: D/AndroidRuntime(2992): Shutting down VM
02-15 01:43:03.544: W/dalvikvm(2992): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-15 01:43:03.733: E/AndroidRuntime(2992): FATAL EXCEPTION: main
02-15 01:43:03.733: E/AndroidRuntime(2992): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test2/com.example.test2.Test2}: java.lang.NullPointerException
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.os.Looper.loop(Looper.java:137)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.ActivityThread.main(ActivityThread.java:5039)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at java.lang.reflect.Method.invokeNative(Native Method)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at java.lang.reflect.Method.invoke(Method.java:511)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at dalvik.system.NativeStart.main(Native Method)
02-15 01:43:03.733: E/AndroidRuntime(2992): Caused by: java.lang.NullPointerException
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.view.View.<init>(View.java:3224)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.view.SurfaceView.<init>(SurfaceView.java:181)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at com.example.test2.Test2.<init>(Test2.java:44)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at java.lang.Class.newInstanceImpl(Native Method)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at java.lang.Class.newInstance(Class.java:1319)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
02-15 01:43:03.733: E/AndroidRuntime(2992):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
02-15 01:43:03.733: E/AndroidRuntime(2992):     ... 11 more
02-15 01:43:11.183: I/Process(2992): Sending signal. PID: 2992 SIG: 9
  • 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-18T22:00:54+00:00Added an answer on June 18, 2026 at 10:00 pm

    You need a SurfaceView to hold your canvas. It’s just like any other view that you can set a LayoutParams.

    activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity" >
        <LinearLayout
            android:id="@+id/myLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </LinearLayout>
    

    MainActivity.java

    package com.sample.androidcrashtest;
    
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.widget.LinearLayout;
    import android.widget.FrameLayout.LayoutParams;
    
    public class MainActivity extends Activity{
    
        Canvas canvas; //Your canvas to draw on
        LinearLayout myLayout; //The layout that holds the surfaceview
        SurfaceView surface;
        SurfaceHolder surfaceHolder;
    
        public void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            setContentView(R.layout.activity_main);
            myLayout = (LinearLayout) findViewById(R.id.myLayout);
    
            LinearLayout.LayoutParams params_surfaceCanvas = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    
            surface = new SurfaceView(this);
            surface.setLayoutParams(params_surfaceCanvas);
    
            //Assign a surfaceholder to the surface
            surfaceHolder = surface.getHolder();
    
            myLayout.addView(surface);
            canvas = new Canvas();
    
            //Call on draw method
            onDraw();
        }
    
        public void onDraw() {
            //Starts a thread
            new Thread(new Runnable() {
                public void run() {
                    while(true) {
                        //Loops until surfaceHolder is valid to use
                        if (surfaceHolder.getSurface().isValid()) {
                            Log.i("Drawing","Drawing"); 
                            //Always lock the canvas if you want to draw in surfaceview
                            canvas = surfaceHolder.lockCanvas();
    
                            Bitmap image1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
                            canvas.drawColor(Color.WHITE); //The background color of the canvas
                            canvas.drawBitmap(image1, 100, 100, null);
    
                            //Don't forget to unlock it after you draw in the surfaceview
                            surfaceHolder.unlockCanvasAndPost(canvas);
    
                            //breaks the while and end the thread.
                            break;
                        }
                    }
                }
            }).start();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have image map that can I move, but this map will be so
I am writing this code to move image left to right, and it working
I want to move image to another x,y position. I try this code but
There is one image on LinearLayout. I have to move that image in any
I have an image that I want to move. I can move the element
I'm trying to animate an image using KineticJS to move across the screen, but
I need to move the image below the blue navigation bar down so that
I'm trying to move an image holder div to specific x and y coordinates
I used following code to move a image it works fine but while moving
I want to move an image around the screen according to the trackball movement.

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.