Reputation: 259
I came across an error today in android studio. I am trying to create a about us screen in the app. The layout xml file has been created. Any help is appreciated. Thanks.
error: cannot resolve method setcontentview(int)
package example.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class AboutFragment extends android.app.Fragment {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
}
}
Upvotes: 7
Views: 28784
Reputation: 133560
Your class extends Fragment
and you have setContentView(R.layout.about_screen);
. setContentView
is a method of Activity class.
Instead inflate about_screen.xml
in onCreateView
of Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.about_screeen, container, false);
return rootView;
}
Upvotes: 16