Need help with Android app mpg calculator

Put your problem here if it does not fit any of the other categories.

Need help with Android app mpg calculator

Postby jemills27 » Thu Apr 28, 2011 5:59 pm

Trying to finish up my code for my app for my class, making a small mpg calculator, it keeps giving me error on my setOnClickListener. Does anyone have any suggestions on my code or know why its saying syntax error?

Error eclipse gives me
Multiple markers at this line
- Syntax error on token "setOnClickListener", = expected after
this token
- Syntax error on token(s), misplaced construct(s)


public class mpgCalculator extends Activity {



final Button mpgbutton = (Button) findViewById(R.id.button1);
final EditText miles = (EditText) findViewById(R.id.editText1);
final EditText gallons = (EditText) findViewById(R.id.editText2);
final TextView display = (TextView) findViewById(R.id.textView1);
double miles_double;
double gallons_double;
double finalCal;


mpgbutton.setOnClickListener(new OnClickListener() {
//error here ^^
public void onClick(View v){

miles_double = Double.parseDouble(miles.getText().toString());
gallons_double = Double.parseDouble(gallons.getText().toString());
finalCal = miles_double / gallons_double;
display.setText(String.valueOf(finalCal));

}
});


}// end class


Thanks
jemills27
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Apr 28, 2011 5:54 pm

Top

Re: Need help with Android app mpg calculator

Postby MrWaqasAhmed » Thu Apr 28, 2011 7:10 pm

There is no issue in your code , may be you didn't import right action listener , make sure you import android.view.View.OnClickListener , and try to implement onClickListener in your class , tell me if it works or not

Regards
MrWaqasAhmed
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Apr 28, 2011 6:46 pm

Re: Need help with Android app mpg calculator

Postby Ahylkova » Thu Sep 05, 2013 6:27 pm

I think that this information is the best.
Ahylkova
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Sep 04, 2013 9:23 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 28 guests