【问题标题】:IllegalArgumentException: No view found for id for fragmentIllegalArgumentException:未找到片段 id 的视图
【发布时间】:2016-01-17 20:50:24
【问题描述】:

这个异常被抛出:

原因:java.lang.IllegalArgumentException:未找到片段 MainActivityFragment{37dff01 #1 id=0x7f0e006b FFTAG} 的 id 0x7f0e006b (com.example.simplegamer003.sunshine.app:id/container) 的视图}

导致异常的代码:

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listView_forecast);
    listView.setAdapter(mForecastAdapter);

    // We'll call our MainActivity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                Intent intent = new Intent(getActivity(), DetailActivity.class)
                        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                                locationSetting, cursor.getLong(COL_WEATHER_DATE)
                        ));
                startActivity(intent);
            }
        }
    });
    return rootView;
}

【问题讨论】:

  • 你解决过这个问题吗?如果有怎么办?

标签: java android


【解决方案1】:

试试这个:View rootView = inflater.inflate(R.layout.fragment_main, null, false);而不是View rootView = inflater.inflate(R.layout.fragment_main, container, false); 我认为containernull。希望对你有帮助

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多