简体   繁体   中英

Error inflating class fragment. What can I do here?

I was coding this program the other day, hoping that the fragment was doing okay, but it isn't. My project is a Relative Layout app where the GPS map will show up on the screen first thing the activity pops up, and then the choices to view some of the Javanese culture of Indonesia (in the form of Grid - Card View combination), will be available for selection.

Here, in this line, I have a class fragment inflation error, according to Logcat:

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_java_island); // Erroring line

    KerisCard = (CardView) findViewById(R.id.KerisCard);
    TradClothesCard = (CardView) findViewById(R.id.TradClothesCard);
    TradHouseCard = (CardView) findViewById(R.id.TradHouseCard);
    TariMerakCard = (CardView) findViewById(R.id.TariMerakCard);



    SupportMapFragment javaMapFragment = (SupportMapFragment) getSupportFragmentManager().
            findFragmentById(R.id.java_island_map);
    javaMapFragment.getMapAsync(this); . . . }

In retrospect, I'm not very familiar to the concept of fragments as the classes I've been attending aren't going too detailed on the usage of fragments. Also, I have to note without the declaring the object references ((CardView) declarations on the onCreate() function), this error would not show up, and the app will be executable as normal.

Instead of making support fragment reference create fragment reference directly and call method from fragment. SampleFragment fragment=new SampleFragment() Fragment.someMethod Here is a confusion Do you want to open fragment in activity? Because you are trying to find fragment from id,so have you created in xml if not then there is problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM