1

I'm new to android. I'm developing a simple calculator application. There is some problem in my code. There is no syntax error. When I run it, it gives some error. Written all code in a try catch but I'm still unable to catch it.

       b1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            //char x = lbldisp.getText().toString().charAt(1);

        try
        {
            String x = lbldisp.getText().toString();
            if(x.charAt(0)=='0' && x.charAt(1)!='.')
            {
                    lbldisp.setText("1");
            }
            else
            {
                lbldisp.setText(x+"1");
            }

        }
        catch(Exception e)
        {
            Toast.makeText(Calculator.this,e.getMessage().toString(), Toast.LENGTH_SHORT).show();
        }
        }
    });
MPelletier
  • 16,256
  • 15
  • 86
  • 137
piyush
  • 69
  • 1
  • 2
  • 8
  • 1
    what's the error you get after running it – rizzz86 May 11 '12 at 13:01
  • how to see the actual error.. – piyush May 11 '12 at 13:12
  • try to look into the LogCat window. You can filter the messages by clicking on the type of message you want to see – rizzz86 May 11 '12 at 14:07
  • Actually I would like to know were the simplest place would be to start developing andriod software. I use Java and eclipse everyday which would make things very easy to start. On my old computer I downloaded a plug-in but it would seemed to work all that good for eclipse. – Doug Hauf Dec 27 '13 at 18:31

1 Answers1

0

Try to replace this string

 if(x.charAt(0)=='0' && x.charAt(1)!='.')

By this String

 if(x.charAt(0).equals("0") && x.charAt(1).equals("."))

You have Converted the value to String so try to use .equals Method.

Bhavin
  • 6,020
  • 4
  • 24
  • 26