Java if else loop problem

Why my else loop is showing unexpected tokens? I couldn’t catch that :slight_smile:
HERE IS MY CODE

package com.example.myandroidapp;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import java.text.DecimalFormat;

public class MainActivity extends AppCompatActivity {
Button ans_btn,again_btn;
TextView showAns;
EditText getValue;
RadioButton C2F,F2C;
Double x;
@SuppressLint(“SetTextI18n”)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ans_btn = (Button) findViewById(R.id.ans_btn);
again_btn = (Button) findViewById(R.id.again_btn);
showAns = findViewById(R.id.showAns);
getValue = (EditText) findViewById(R.id.getValue);
C2F = (RadioButton) findViewById(R.id.C2F);
F2C = (RadioButton) findViewById(R.id.F2C);
ans_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getValue.getText().toString().isEmpty())
showAns.setText(“Please give any temperature:”);
}

            else

        {

            x = Double.parseDouble(String.valueOf(getValue.getText()));
            if (C2F.isChecked()) {
                x = (x * 9) / 5 + 32;
                x = Double.parseDouble(new DecimalFormat("##.###").format(x));
                showAns.setText(String.valueOf(x) + "Degree F");
            } else if (F2C.isChecked()) {
                x = (x - 32) * 5 / 9;
                showAns.setText(String.valueOf(x) + "Degree C");
            } else {
                showAns.setText("Please Select an option...");
            }

        }


    });
    ans_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showAns.setText("0.0");
            getValue.setText("");
            C2F.setChecked(false);
            F2C.setChecked(false);
        }

    });
}

}
WIth Screenshot

It looks like there’s a { missing for the previous if-statement.

1 Like