Reputation: 9825
I have a fragment called ProfilePicBtn and Im trying to load it in my fragment class called HomeFragment. But when I try and instantiate an instance of ProfilePicBtn I get an error saying unreachable statement. Note Im trying to follow the developer docs here.
package com.example.adam.hilo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
public class HomeFragment extends Fragment {
public HomeFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home, container, false);
Fragment profileBtnFragment = new ProfileBtnFragment();
}
}
Upvotes: 0
Views: 189
Reputation: 1672
Change order of statements of onCreateView() .
public class HomeFragment extends Fragment {
public HomeFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.fragment_home, container, false);
Fragment profileBtnFragment = new ProfileBtnFragment();
return view ;
}
}
Upvotes: 0
Reputation: 1135
This code has an unconditional return statement before the line which allocates the new ProfileBtnFragment. So the second line is unreachable.
Upvotes: 1