Geore Shg
Geore Shg

Reputation: 1329

Fragment.instantiate fatal exception

I have the following code:

 import android.support.v4.app.FragmentActivity;
 import android.support.v4.app.Fragment;

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


    List<Fragment> fList = new Vector<Fragment>();
    fList.add(Fragment.instantiate(this, "All"));

which is a fatal exception. If i remove line fList.add(Fragment.instantiate(this, "All"));, it's fine. So what's happening? I have no idea how to use fragments so I'm guessing my problem is a nooby one.

Upvotes: 2

Views: 524

Answers (2)

Alex Lockwood
Alex Lockwood

Reputation: 83311

If your Fragment is a nested inner class, make sure you have declared it to be a public static class. Likewise, make sure the Fragment is named All.

That being said, I hope you know what you are doing, because I can't imagine a scenario in which I would store a Vector of Fragments. At the very least you should use an ArrayList instead.

Also, you should post the exact error message you are getting, along with the rest of your logcat output.

Upvotes: 1

rajpara
rajpara

Reputation: 5203

If you want to add Fragment class instance in fList then below code will help you.

fList.add(Fragment.instantiate(this, Your-Fragment-Class-Name.class.getName()));

Upvotes: 2

Related Questions