0

I wanted to move an image . I did like this to move the image in the onTouch event

        float downx = 0;
float downy = 0;
float upx = 0;
float upy = 0;

public boolean onTouch(View v, MotionEvent event) { 
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        downx = event.getX();
        downy = event.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        upx = event.getX();
        upy = event.getY();


        CompositeImageViewText.invalidate();
                canvas.drawBitmap(bmw, upx,upy, paint);
         CompositeImageViewText.setImageBitmap(bmw);
        downx = upx;
        downy = upy;
        break;
    case MotionEvent.ACTION_UP:
        upx = event.getX();
        upy = event.getY(); 
        break;
    case MotionEvent.ACTION_CANCEL:
        break; 
    default:
        break; 
    }

    return true;
}

But i experienced a force close on doing this . What could have been the issue?Is my code correct?

the logcat is pasted below

01-05 02:08:30.995: E/AndroidRuntime(1240):     at com.apress.proandroidmedia.ch3.choosepicturecomposite.ChoosePictureComposite.onTouch(ChoosePictureComposite.java:335)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.View.dispatchTouchEvent(View.java:3881)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.os.Looper.loop(Looper.java:130)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at java.lang.reflect.Method.invoke(Method.java:507)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-05 02:08:30.995: E/AndroidRuntime(1240):     at dalvik.system.NativeStart.main(Native Method)
Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
Ashish Augustine
  • 1,784
  • 4
  • 20
  • 50
  • hi, i have posted the logcat above – Ashish Augustine Jan 04 '12 at 20:48
  • Please post the rest of the error log, in particular the error message itself. – Pedantic Jan 04 '12 at 20:54
  • It's hard to tell because the top line of the error (the one that tells you what type of exception was thrown) seems to be missing from the logcat output. It would also be helpful to know which line is 335 in the file, since that's where the error occurred. From what I can see, though, the only item that may not have been defined is `canvas`, so you may be getting a NullPointerException there. – devunwired Jan 04 '12 at 20:56
  • line 335 is canvas.drawBitmap(bmw, upx,upy, paint); and the canvas is declared too.. – Ashish Augustine Jan 04 '12 at 21:07
  • when i remove the line 335 there is no force close. but there ocurs nothing too.. – Ashish Augustine Jan 04 '12 at 21:08
  • you need to post a better logcat error, there is NO conclusive error in the log. Post more than what you posted. – JoxTraex Jan 04 '12 at 21:28
  • i have put the full code here http://stackoverflow.com/questions/8746554/drag-a-bitmap-generated-during-programme-run please help over it – Ashish Augustine Jan 05 '12 at 17:45
  • You can try this out: http://stackoverflow.com/questions/4255859/touch-and-drag-image-in-android – MiStr Jun 01 '12 at 17:56

0 Answers0