App Force Closes - Help - Beginner


Last Updated:

  1. arshad115

    arshad115 New Member This Topic's Starter

    Joined:
    Sep 12, 2010
    Messages:
    1
    Likes Received:
    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. :(
     

    Advertisement

Share This Page

Loading...