1 Replies - 473 Views - Last Post: 07 July 2013 - 09:07 PM

#1 faithism  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-July 13

eclipse Temp Converter,error:cannot make a static reference

Posted 07 July 2013 - 08:59 PM

I am making a android eclipse Temp Converter for Fahrenheit to Celsius. The onclick view method, my code errors out with "Cannot make a static reference to the non-static method getText() from the type EditText.
MainActivity.Java code:
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements onclickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		EditText editFahrenheit = (EditText) findViewById(R.id.editFahrenheit);
		EditText editCelsius = (EditText) findViewById(R.id.editCelsius);
		TextView textFahrenheit = (TextView) findViewById(R.id.textFahrenheit);
		TextView textCelsius = (TextView) findViewById(R.id.textCelsius);
		Button buttonConvert = (Button) findViewById(R.id.buttonConvert);
		buttonConvert.setonclickListener(this);
		
		
;	}

	@Override
	public void onclick(View v) {
		// TODO Auto-generated method stub
		Double Celsius = Double.parseDouble(EditText.getText().toString());  //ERRORS  EditText.getText.
		Celsius = ((Celsius - 32) * 5) / 9;
		textCelsius.setText(Celsius.toString());














Is This A Good Question/Topic? 0
  • +

Replies To: eclipse Temp Converter,error:cannot make a static reference

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,258
  • Joined: 27-December 08

Re: eclipse Temp Converter,error:cannot make a static reference

Posted 07 July 2013 - 09:07 PM

Moved to Android.

Rather than EditText.getText(), you have to getText() on the specific EditText object (so editTextVariable.getText()). Remember that text is associated with each individual text field, not the EditText class itself.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1