`an error keeps saying "constant expression required" preventing me from running the app on a device to further develop the app.
am trying to create a sort of google pay.. so i need the selected amounts. but am getting an error saying "constant expression required".. the variable is declared private and not final so i dont know why am getting this error. the value is not even highlighted showing that it is being used. how can i solve this error. i tried innitialising the variable to zero but it still does not help.. `
package com.example.greenearth;
import android.media.Image;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class Donations extends Fragment {
RadioGroup radioGroup;
RadioButton minimum;
RadioButton average;
RadioButton maximum;
private int google_amount=0;
RelativeLayout rl;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_donations, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
radioGroup=view.findViewById(R.id.select);
minimum=view.findViewById(R.id.fifty);
average=view.findViewById(R.id.five_hundred);
maximum=view.findViewById(R.id.ten_thousand);
rl=view.findViewById(R.id.donater);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.fifty:
google_amount=50;
break;
case R.id.five_hundred:
google_amount=500;
break;
case R.id.ten_thousand:
google_amount=10000;
break;
}
}
});
rl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (google_amount>0) {
//googlepay
} else {
Toast.makeText(getContext(),"Please choose an amount", Toast.LENGTH_SHORT).show();
}
}
});
}
}