android - Don't know why the app is crashing -


i have written code, keeps on crashing, don't know point onwards. here code:

public class mainactivity extends activity {     int windowwidth;     int screencenter;     int x_cord, y_cord, x, y;     int likes = 0;     relativelayout parentview;     float alphavalue = 0;     private context m_context;      @suppresswarnings("deprecation")     @suppresslint("newapi")     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         requestwindowfeature(window.feature_no_title);         setcontentview(r.layout.mainlayout);         m_context = mainactivity.this;          parentview = (relativelayout) findviewbyid(r.id.layoutview);         windowwidth = getwindowmanager().getdefaultdisplay().getwidth();         screencenter = windowwidth / 2;         int[] myimagelist = new int[] { r.drawable.cats, r.drawable.baby1, r.drawable.sachin,                 r.drawable.cats, r.drawable.puppy };          (int = 0; < 5; i++) {             layoutinflater inflate = (layoutinflater) m_context                     .getsystemservice(context.layout_inflater_service);              final view m_view = inflate.inflate(r.layout.custom_layout, null);             imageview m_image = (imageview) m_view.findviewbyid(r.id.sp_image);             linearlayout m_toplayout = (linearlayout) m_view.findviewbyid(r.id.sp_color);             linearlayout m_bottomlayout = (linearlayout) m_view.findviewbyid(r.id.sp_linh);             // final relativelayout myrelview = new relativelayout(this);             m_view.setlayoutparams(new layoutparams((windowwidth - 80), 450));             m_view.setx(40);             m_view.sety(40);             m_view.settag(i);             m_image.setbackgroundresource(myimagelist[i]);              if (i == 0) {                 m_view.setrotation(-1);             } else if (i == 1) {                 m_view.setrotation(-5);              } else if (i == 2) {                 m_view.setrotation(3);              } else if (i == 3) {                 m_view.setrotation(7);              } else if (i == 4) {                 m_view.setrotation(-2);              } else if (i == 5) {                 m_view.setrotation(5);              }              // add dynamically button on image.             final button imagelike = new button(m_context);             imagelike.setlayoutparams(new layoutparams(100, 50));             imagelike.setbackgrounddrawable(getresources().getdrawable(r.drawable.like));             imagelike.setx(20);             imagelike.sety(-250);             imagelike.setalpha(alphavalue);             m_toplayout.addview(imagelike);              // add dynamically dislike button on image.             final button imagepass = new button(m_context);             imagepass.setlayoutparams(new layoutparams(100, 50));             imagepass.setbackgrounddrawable(getresources().getdrawable(r.drawable.dislike));              imagepass.setx(260);             imagepass.sety(-300);             imagepass.setalpha(alphavalue);             m_toplayout.addview(imagepass);              // click listener on bottom layout open details of             // image.             m_bottomlayout.setonclicklistener(new onclicklistener() {                  @override                 public void onclick(view v) {                     startactivity(new intent(m_context, detailsactivity.class));                  }             });              // touch listener on image layout swipe image right or left.             m_toplayout.setontouchlistener(new ontouchlistener() {                  @override                 public boolean ontouch(view v, motionevent event) {                     x_cord = (int) event.getrawx();                     y_cord = (int) event.getrawy();                      m_view.setx(x_cord - screencenter + 40);                     m_view.sety(y_cord - 150);                     switch (event.getaction()) {                     case motionevent.action_down:                         x = (int) event.getx();                         y = (int) event.gety();                         log.v("on touch", x + " " + y);                         break;                     case motionevent.action_move:                         x_cord = (int) event.getrawx(); // updated more                                                         // smoother animation.                         y_cord = (int) event.getrawy();                         m_view.setx(x_cord - x);                         m_view.sety(y_cord - y);                         // m_view.sety(y_cord-y);                         // y_cord = (int) event.getrawy();                         // m_view.setx(x_cord - screencenter + 40);                         // m_view.sety(y_cord - 150);                         if (x_cord >= screencenter) {                             m_view.setrotation((float) ((x_cord - screencenter) * (math.pi / 32)));                             if (x_cord > (screencenter + (screencenter / 2))) {                                 imagelike.setalpha(1);                                 if (x_cord > (windowwidth - (screencenter / 4))) {                                     likes = 2;                                 } else {                                     likes = 0;                                 }                             } else {                                 likes = 0;                                 imagelike.setalpha(0);                             }                             imagepass.setalpha(0);                         } else {                             // rotate                             m_view.setrotation((float) ((x_cord - screencenter) * (math.pi / 32)));                             if (x_cord < (screencenter / 2)) {                                 imagepass.setalpha(1);                                 if (x_cord < screencenter / 4) {                                     likes = 1;                                 } else {                                     likes = 0;                                 }                             } else {                                 likes = 0;                                 imagepass.setalpha(0);                             }                             imagelike.setalpha(0);                         }                          break;                     case motionevent.action_up:                         x_cord = (int) event.getrawx();                         y_cord = (int) event.getrawy();                          log.e("x point", "" + x_cord + " , y " + y_cord);                         imagepass.setalpha(0);                         imagelike.setalpha(0);                          if (likes == 0) {                             // log.e("event status", "nothing");                             m_view.setx(40);                             m_view.sety(40);                             m_view.setrotation(0);                         } else if (likes == 1) {                             // log.e("event status", "passed");                             parentview.removeview(m_view);                         } else if (likes == 2) {                              // log.e("event status", "liked");                             parentview.removeview(m_view);                         }                         break;                     default:                         break;                     }                     return true;                 }             });              parentview.addview(m_view);          }     } } 

here logcat

04-29 13:33:37.516: e/androidruntime(8930): fatal exception: main 04-29 13:33:37.516: e/androidruntime(8930): java.lang.nosuchmethoderror: android.view.view.setx 04-29 13:33:37.516: e/androidruntime(8930):     @ com.example.tinderview_demo.mainactivity.oncreate(mainactivity.java:55) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1072) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.app.activitythread.performlaunchactivity(activitythread.java:1836) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:1893) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.app.activitythread.access$1500(activitythread.java:135) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.app.activitythread$h.handlemessage(activitythread.java:1054) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.os.handler.dispatchmessage(handler.java:99) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.os.looper.loop(looper.java:150) 04-29 13:33:37.516: e/androidruntime(8930):     @ android.app.activitythread.main(activitythread.java:4389) 04-29 13:33:37.516: e/androidruntime(8930):     @ java.lang.reflect.method.invokenative(native method) 04-29 13:33:37.516: e/androidruntime(8930):     @ java.lang.reflect.method.invoke(method.java:507) 04-29 13:33:37.516: e/androidruntime(8930):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:849) 04-29 13:33:37.516: e/androidruntime(8930):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:607) 04-29 13:33:37.516: e/androidruntime(8930):     @ dalvik.system.nativestart.main(native method) 

i hope finds solution me. grateful.

thankyou in advance

java.lang.nosuchmethoderror: android.view.view.setx

setx available api level 11, , run code older device or on emulator older sdk. should viewcompat class, port of methods. e.g.

viewcompat.setx(m_view, 40)  

not of them back-ported on version of android, @ least avoid nosuchmethoderrorexception. way check explicitly against sdk_int

if (android.os.build.version.sdk_int >= android.os.build.version_codes. honeycomb) {       // run starting honeycomb } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -