error: cannot find symbol method setContentView(int)

error: cannot find symbol method setContentView(int)

我是 Android Studio 的新手。我遇到 setContentView 的问题。 我知道它在 Fragment 中不起作用。

有人知道如何解决这个问题吗?

错误:

error: cannot find symbol method setContentView(int)

代码:

public class Tab1Fragment extends Fragment{
    private static final String TAG = "Tab1Fragment";


    Toolbar mToolbar;
    ListView mListView;

    String[] countryNames = {"Australia", "Brazil", "China", "France", "Germany", "India", "Ireland", "Italy"
            , "Mexico", "Poland", "Russia", "Spain", "US"};
    int[] countryFlags = {R.drawable.flag_australia,
            R.drawable.flag_brazil,
            R.drawable.flag_china,
            R.drawable.flag_france,
            R.drawable.flag_germany,
            R.drawable.flag_india,
            R.drawable.flag_ireland,
            R.drawable.flag_italy,
            R.drawable.flag_maxico,
            R.drawable.flag_poland,
            R.drawable.flag_russia,
            R.drawable.flag_spain,
            R.drawable.flag_us};


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment1_layout);

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitle("My Application");
        mListView = (ListView) findViewById(R.id.listview);
        MyAdapter myAdapter = new MyAdapter(Tab1Fragment.this, countryNames, countryFlags);
        mListView.setAdapter(myAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent mIntent = new Intent(Tab1Fragment.this, DetailActivity.class);
                mIntent.putExtra("countryName", countryNames[i]);
                mIntent.putExtra("countryFlag", countryFlags[i]);
                startActivity(mIntent);
            }
        });
    }

    private Button btnTEST;
}

在 fragment 中,您膨胀布局而不是 setContentView 代码可能看起来像这样

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment1_layout, container, false);

      // Put your fragment code here

        return rootView;
    }