Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't understand what's wrong here

Java
fragment.setArguments(args);
FragmentManager frgManager = getFragmentManager();
frgManager.beginTransaction().replace(R.id.content_frame,fragment).commit();


At the beginning of MainActivity.java I
Java
import android.app.FragmentManager;

Android studio throws an error stating that I have the wrong 2ns argument type.
It says that the 2nd argument requires a type of android.app.Fragment which makes little sense to me since I imported android.app.FragmentManager in the beginning.

Honestly I don't know what difference between android.support.v4.app.Fragment and android.app.Fragment is so I don't know where to begin.

I'm following this tutorial.

I've searched around for a solution but no one appears to have a similar problem.

Update:
Android development is a new experience for me and I'm still trying to understand how the everything fits in together and it's quite overwhelming, so am sorry if I've disappointed some people.
Posted
Updated 13-May-15 19:28pm
v5
Comments
Sergey Alexandrovich Kryukov 14-May-15 1:02am    
It's hard to help you. Apparently, you cannot see the difference between type and namespace, between two different types, and so on. It sounds like you need to learn programming pretty much from the very beginning.
—SA
pyler 14-May-15 1:22am    
Not to worry, I solved the problem and it does sound like I need to learn programming from the very beginning but I can assure you that I don't. I know what I know and what I need to know.
Sergey Alexandrovich Kryukov 14-May-15 10:27am    
Very good. I'm glad if I was wrong; you have just been a bit confused.
—SA

1 solution

Solved the problem by importing
FragmentActivity
and having my main function extend it

import android.support.v4.app.FragmentActivity;
.
.
.
public class MainActivity extends FragmentActivity


I think android studio was extending the default Activity instead of the FragmentActivity.

I also changed
FragmentManager frgManager = getFragmentManager();
to
FragmentManager frgManager = getSupportFragmentManager();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900