Why do I get the error that line 92 is an unreachable statement? The error is in this line:
final RadioButton r1 =
We don't put return
statement above any other statement unless that return
is under any conditional statement. If we do that then all the statements below that would never get executed (means it would become unreachable under all circumstances) which causes the error you are getting.
Do it like this
public class TabFragmentA extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RelativeLayout rootView = (RelativeLayout) inflater.inflate(R.layout.tab_layout_a, container, false);
final RadioButton r1 = (RadioButton) rootView.findViewById(R.id.radio1);
final RadioButton r2 = (RadioButton) rootView.findViewById(R.id.radio2);
final ImageView iv1 = (ImageView) rootView.findViewById(R.id.iv1);
final ImageView iv2 = (ImageView) rootView.findViewById(R.id.iv2);
iv1.setVisibility(View.INVISIBLE);
iv2.setVisibility(View.INVISIBLE);
r1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(r1.isChecked())
{
r2.setChecked(false);
iv2.setVisibility(View.INVISIBLE);
iv1.setVisibility(View.VISIBLE);
}
}
});
r2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(r2.isChecked())
{
r1.setChecked(false);
iv1.setVisibility(View.INVISIBLE);
iv2.setVisibility(View.VISIBLE);
}
}
});
return rootView;
}
}
The return statement should be at the end:
final RadioButton r1 = (RadioButton) getView().findViewById(R.id.radio1);
final RadioButton r2 = (RadioButton) getView().findViewById(R.id.radio2);
return (RelativeLayout) inflater.inflate(R.layout.tab_layout_a, container, false);
You have a return right above it. When you return from a method nothing below it will get executed. That means the line below it will never get executed.
The compiler is trying to help you see this.