Android Studio Java - Which modifier should I use? -
i'm kind of new android studio , java bear me please.
i'm making app can keep scores dart game. have switch statement button clicked. when enter button pressed, want go java file while using 1 argument, input. apparently use both static , non static methods , wrong. how fix this?
here first java file, witch screen file:
package com.example.jeroe.darts; import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.textview; import com.example.jeroe.darts.score; public class matchscreen extends appcompatactivity implements view.onclicklistener{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.content_match_screen); defineeventhandlers(); } public void onclick(view v) { textview inputtrue = (textview) findviewbyid(r.id.textviewinput); textview edittextscore = (textview) findviewbyid(r.id.edittextscore); switch (v.getid()) { case r.id.textviewinnerbull: edittextscore.append("50"); break; case r.id.textviewouterbull: edittextscore.append("25"); break; case r.id.textviewclear: edittextscore.settext(""); break; case r.id.textviewenter: score.enter(edittextscore.gettext()); // here error: //non-static method 'enter(charsequence)' cannot referenced static context } } public void defineeventhandlers() { // declare textviews player 1 textview textviewpl1score = (textview) findviewbyid(r.id.textviewpl1score); textview pl1dart1 = (textview) findviewbyid(r.id.pl1dart1); textview pl1dart2 = (textview) findviewbyid(r.id.pl1dart2); textview pl1dart3 = (textview) findviewbyid(r.id.pl1dart3); // declare textviews player 2 textview textviewpl2score = (textview) findviewbyid(r.id.textviewpl2score); textview pl2dart1 = (textview) findviewbyid(r.id.pl2dart1); textview pl2dart2 = (textview) findviewbyid(r.id.pl2dart2); textview pl2dart3 = (textview) findviewbyid(r.id.pl2dart3); //t20, bulls textview textviewouterbull = (textview) findviewbyid(r.id.textviewouterbull); textviewouterbull.setonclicklistener(this); textview textviewinnerbull = (textview) findviewbyid(r.id.textviewinnerbull); textviewinnerbull.setonclicklistener(this); //enter, backspace textview textviewclear = (textview) findviewbyid(r.id.textviewclear); textviewclear.setonclicklistener(this); textview textviewenter = (textview) findviewbyid(r.id.textviewenter); textviewenter.setonclicklistener(this); } } //end of file
then need go file called score.java. here want keep score , other things:
package com.example.jeroe.darts; public class score { int pl1score = 501; boolean player1 = true; public void enter(charsequence input) { int intinput = inputconverter(input); if (player1 == true) //de input = player 1 { // } } public int inputconverter(charsequence input) { int input = integer.parseint(input.tostring()); return input; } }
how fix this?
//non-static method 'enter(charsequence)' cannot referenced static context
it means need instance of score:
score score = new score(); score.enter(edittextscore.gettext());
Comments
Post a Comment