android - NullPointException in drag and drop of ImageView -


i want move image 1 place another.

now image held imageview , drawing drag , drop ondraglistener return null point exception , application got crash there other way implement drag , drop , solution problem.

here main activity code:

@override public void oncreate(bundle savedinstancestate) {     setcontentview(r.layout.activity_main);      ima = (imageview)findviewbyid(r.id.iv_logo);      ima.settag(imageview_tag);      ima.setonlongclicklistener(new view.onlongclicklistener() {         @override         public boolean onlongclick(view v) {             clipdata.item item = new clipdata.item((charsequence)v.gettag());              string[] mimetypes = {clipdescription.mimetype_text_plain};             clipdata dragdata = new clipdata(v.gettag().tostring(),                     mimetypes, item);              // instantiates drag shadow builder.             view.dragshadowbuilder myshadow = new dragshadowbuilder(ima);              // starts drag             v.startdrag(dragdata,  // data dragged                     myshadow,  // drag shadow builder                     null,      // no need use local data                     0          // flags (not used, set 0)             );             return true;         }     }); } 

this drag , drop code:

ima.setondraglistener( new ondraglistener(){     @override     public boolean ondrag(view v,  dragevent event){         switch(event.getaction())         {             case dragevent.action_drag_started:                 layoutparams = (relativelayout.layoutparams)                         v.getlayoutparams();                 log.d(msg, "action dragevent.action_drag_started");                 break;              case dragevent.action_drag_entered:                 log.d(msg, "action dragevent.action_drag_entered");                 int x_cord = (int) event.getx();                 int y_cord = (int) event.gety();                 break;              case dragevent.action_drag_exited :                 log.d(msg, "action dragevent.action_drag_exited");                 x_cord = (int) event.getx();                 y_cord = (int) event.gety();                 layoutparams.leftmargin = x_cord;                 layoutparams.topmargin = y_cord;                 v.setlayoutparams(layoutparams);                 break;              case dragevent.action_drag_location  :                 log.d(msg, "action dragevent.action_drag_location");                 x_cord = (int) event.getx();                 y_cord = (int) event.gety();                 break;              case dragevent.action_drag_ended   :                  break;              case dragevent.action_drop:                  break;              default: break;         }         return true;     } }); 

i forget in activity:

super.oncreate(savedinstancestate); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -