I am aware this issue has been brought up and resolved multiple times but none of the solution I looked at helped me so here comes again:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View rootView = inflater.inflate(R.layout.fragment_home_screen, container, false);
try {
userInfo = (TextView) rootView.findViewById(R.id.showData);
user myUser = new user();
userInfo.setText(myUser.getUserInfo());
}
catch(Exception e){
System.out.println("ERROR: "+e.getMessage());
}
return rootView;
}
That is my fragment (the default created by Android Studio with minor edits). The corresponding XML layout is this:
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".HomeScreen$PlaceholderFragment">
<TextView android:id="@+id/showData"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
The error I'm getting:
03-19 08:23:09.119 29125-29125/com.app.myAPP I/System.out﹕ ERROR: null
03-19 08:23:12.296 29125-29125/com.app.myAPP I/System.out﹕ ERROR: null
The TextView is created in OnCreateView() instead of onCreate() which seems to cause a null return most of the time.
Any help is appreciated.
0 comments:
Post a Comment