EDIT: Yes I've sort of re-posted this but if you read the two posts, they both point to different issues with (hopefully) the same cause. In my other question, a particular widget is null. Here, the entire getView funtion is returning null.
I've been working on this for hours now. Can't find any reason. I can't post the entire fragment here but the following should make it clear.
@BindView(R.id.acService) AutoCompleteTextView autocompleteService;
@BindView(R.id.acAddress) AutoCompleteTextView autocompleteAddress;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_home, container, false);
unbinder = ButterKnife.bind(this, view);
initialize();
loadSkillsData();
return view;
}
private void initialize()
{
context = getActivity();
util = new Util(context);
requestService = new RequestService();
geoDataClient = Places.getGeoDataClient(context, null);
autocompleteAdapter = new PlaceAutocompleteAdapter(context, geoDataClient, BOUNDS_ONTARIO, null);
autocompleteAddress.setAdapter(autocompleteAdapter);
mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment);
mapFragment.getMapAsync(this);
}
private void loadSkillsData()
{
Realm realm = getRealm();
UserModel user = realm.where(UserModel.class).findFirst();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(RestAPI.ENDPOINT)
.addConverterFactory(MoshiConverterFactory.create())
.build();
RestAPI restApi = retrofit.create(RestAPI.class);
Call<ResponseSkills> loginCall = restApi.getSkills(user.getServerUserId());
loginCall.enqueue(new Callback<ResponseSkills>()
{
@Override
public void onResponse(Call<ResponseSkills> call, final Response<ResponseSkills> response)
{
if (response.isSuccessful())
{
if (response.body().getStatus())
{
skillList = response.body().getSkillList();
ArrayAdapter<SkillModel> skillAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, skillList);
AutoCompleteTextView acService = getView().findViewById(R.id.acService);
acService.setAdapter(skillAdapter);
}
else
{
switch (response.body().getError())
{
default:
Toasty.error(context, response.body().getError());
break;
}
}
} else
{
Toasty.error(context, getString(R.string.toast_experienced_a_problem)).show();
}
}
@Override
public void onFailure(Call<ResponseSkills> call, Throwable t)
{
Toasty.error(context, getString(R.string.toast_experienced_a_problem)).show();
t.printStackTrace();
}
});
}
On the line AutoCompleteTextView acService = getView().findViewById(R.id.acService);, I get a NPE saying that getView is returning null.
Why is this that so?