0

I am creating an app that connects from my database(000webhost) and I am using this for the http url connection .

And here's my code

public class RegisterFragment extends Fragment {

    public RegisterFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_register, container, false);

        //Start ProgressBar first (Set visibility VISIBLE)
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
                if (fetchData.startFetch()) {
                    if (fetchData.onComplete()) {
                        String result = fetchData.getResult();
                        //End ProgressBar (Set visibility to GONE)

                    }
                }
            }
        });
    }
}

And it is telling me that the Handler part is

Unreachable Statement

Could someone point out why it is having an error. Thank you in advance

1 Answers1

1

You have a return statement just above the Handler code.

return inflater.inflate(R.layout.fragment_register, container, false);

Therefore the function will return before ever reaching the Handler.

Explaination: https://www.geeksforgeeks.org/return-keyword-java/

vvvv
  • 26
  • 2