• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps App Force Closes - Help - Beginner

arshad115

Lurker
Sep 12, 2010
1
0
Hi,I am new to android development and I have made this using help
from a website.
Please Help,Thanks.
The XML files dont have any errors,Here is my Main java code:
package com.CFConverter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class CFConverter extends Activity {
/** Called when the activity is first created. */
private EditText text;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

text = (EditText) findViewById(R.id.EditText01);



}

//This Handler is called when we click the button01.

public void myClickHandler(View view) //passing the current view
{


if(view.getId()== R.id.Button01)
{

RadioButton celsiusButton =
(RadioButton)findViewById(R.id.RadioButton01);
RadioButton farhrenheitButton =
(RadioButton)findViewById(R.id.RadioButton02);
if(text.getText().length()==0)
{
Toast.makeText(this, "Please Enter a Valid Number",
Toast.LENGTH_LONG);
return;
}
float inputValue = Float.parseFloat(text.getText().toString());
if(celsiusButton.isChecked())
{
text.setText(String.valueOf(convertCToF(inputValue))); //
calling function to convert
}
else
{
text.setText(String.valueOf(convertFToC(inputValue)));
}
return;
}


}


private float convertCToF(float fahrenheit)
{
return ((fahrenheit - 32) * 5 / 9);
}
private float convertFToC(float celsius)
{
return ((celsius * 9) / 5) + 32;
}



}


I was searching for the error on the internet,I read somewhere that
when you use findViewbyId(),you need to use setContentView().But I
dont know how to use it. :(
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones