android - Class must either be declared abstract or implement abstract method? -


it loos i'm doing right here must missing something. hoping explanation why i'm getting error in first line of code , should fix type of problem? i'm new android dev.

public class page2 extends appcompatactivity implements onclicklistener {   /**  * attention: auto-generated implement app indexing api.  * see https://g.co/appindexing/androidstudio more information.  */ private googleapiclient client;  imagebutton rock, scissors, paper; random randomnum = new random(); int cpumov;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activitypage2); //set xml page style display      rock = (imagebutton) findviewbyid(r.id.imagebuttonrock);     scissors = (imagebutton) findviewbyid(r.id.imagebuttonscissors);     paper = (imagebutton) findviewbyid(r.id.imagebuttonpaper);      rock.setonclicklistener(new onclicklistener() { // calling onclick() method         @override         //method handling happens when click rock buttonimage.         public void onclick(view v) {              // number between 1-3 inclusive (max-min+1)+1             cpumov = randomnum.nextint(3 - 1 + 1) + 1;             buildalert(cpumov, "imagebuttonrock");             moveviewtoscreencenter(v);//float center         }     });      scissors.setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {              // number between 1-3 inclusive (max-min+1)+1             cpumov = randomnum.nextint(3 - 1 + 1) + 1;             buildalert(cpumov, "imagebuttonscissors");             moveviewtoscreencenter(v);//float center         }     });      paper.setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {              // number between 1-3 inclusive (max-min+1)+1             cpumov = randomnum.nextint(3 - 1 + 1) + 1;             buildalert(cpumov, "imagebuttonpaper");             moveviewtoscreencenter(v);//float center         }     });  } //eooncreate  private void moveviewtoscreencenter( view view ) {     relativelayout root = (relativelayout) findviewbyid( r.id.rootlayout );     displaymetrics dm = new displaymetrics();     this.getwindowmanager().getdefaultdisplay().getmetrics( dm );     int statusbaroffset = dm.heightpixels - root.getmeasuredheight();      int originalpos[] = new int[2];     view.getlocationonscreen( originalpos );      int xdest = dm.widthpixels/2;     xdest -= (view.getmeasuredwidth()/2);     int ydest = dm.heightpixels/2 - (view.getmeasuredheight()/2) - statusbaroffset;      translateanimation anim = new translateanimation( 0, xdest - originalpos[0] , 0, ydest - originalpos[1] );     anim.setduration(5000); // speed of movement     anim.setfillafter( true );     view.startanimation(anim); }  //builds message displayed void appendmessage(alertdialog.builder myalert, string cpumove, string result) {     myalert.setmessage("computer selects " +cpumove+ ", " +result+ "!");     myalert.show();     myalert.setcancelable(true);     //how give id alertdialog save in strings.xml  }  public void buildalert(int move, string btnpressed) {     alertdialog.builder myalert = new alertdialog.builder(this);     string cpumove;     string result;     if (btnpressed.equals("imagebuttonrock")) {         //toast.maketext(this, "hooray "+move, toast.length_short).show();         if (move == 1) {             cpumove = "rock";             result = "tied";             //call appendmessage append vars , display message             appendmessage(myalert, cpumove, result);         }         if (move == 2) {             cpumove = "scissors";             result = "won";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }         if (move == 3) {             cpumove = "paper";             result = "lost";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }     } else if (btnpressed.equals("imagebuttonscissors")) {         if (move == 1) {             cpumove = "rock";             result = "lost";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }         if (move == 2) {             cpumove = "scissors";             result = "tied";             //call appendmessage append vars , display message             appendmessage(myalert, cpumove, result);         }         if (move == 3) {             cpumove = "paper";             result = "won";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }     } else { //imagebutton scissors         if (move == 1) {             cpumove = "rock";             result = "won";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }         if (move == 2) {             cpumove = "scissors";             result = "lost";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }         if (move == 3) {             cpumove = "paper";             result = "tied";             //call appendmessage append vars , display message             appendmessage(myalert,cpumove,result);         }     } }  @override public void onstart() {     super.onstart();      // attention: auto-generated implement app indexing api.     // see https://g.co/appindexing/androidstudio more information.     client.connect();     action viewaction = action.newaction(             action.type_view, // todo: choose action type.             "page2 page", // todo: define title content shown.             // todo: if have web page content matches app activity's content,             // make sure auto-generated web page url correct.             // otherwise, set url null.             uri.parse("http://host/path"),             // todo: make sure auto-generated app deep link uri correct.             uri.parse("android-app://rps.rsp/http/host/path")     );     appindex.appindexapi.start(client, viewaction); }  @override public void onstop() {     super.onstop();      // attention: auto-generated implement app indexing api.     // see https://g.co/appindexing/androidstudio more information.     action viewaction = action.newaction(             action.type_view, // todo: choose action type.             "page2 page", // todo: define title content shown.             // todo: if have web page content matches app activity's content,             // make sure auto-generated web page url correct.             // otherwise, set url null.             uri.parse("http://host/path"),             // todo: make sure auto-generated app deep link uri correct.             uri.parse("android-app://rps.rsp/http/host/path")     );     appindex.appindexapi.end(client, viewaction);     client.disconnect(); } 

}

i know view.onclicklistener must implement function onclick(). not doing that?

you need implement unimplemented methods interface you're implementing. in case interface onclicklistener , needs have method:

public abstract void onclick (view v)

either remove interface or implement method. can placing cursor on onclicklistener , pressing alt+enter if you're using android studio , it'll give options on how fix error.

as can see in code, you've given buttons proper onclicklisteners solution might delete implements onclicklistener since you're not using it.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -