hey I’m new to programming so I thought I would just make a simple c to f converter but it keeps crashing on the emulator before I open it can anyone see why? i know the codes probally all wrong but its the only way i could think of doing it
package com.jamie.convert;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class ConvertorActivity extends Activity implements OnClickListener {
TextView textout1;
EditText textIn1;
Button convert;
int x=Integer.parseInt(textIn1.getText().toString());
double fahrenheit = 1.8*x;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
convert = (Button) findViewById(R.id.convert);
textIn1=(EditText) findViewById(R.id.input);
textout1=(TextView) findViewById(R.id.output);
convert.setOnClickListener((android.view.View.OnClickListener)this);
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.convert) {
textout1.setText(""+fahrenheit);
}
}
}
use this code instead of this you’ll get the answer
This would heppened due to your int x would not be getting any value from the edittext.