The phrase "have trouble in doing something" can be broken down as follows:

1. Meaning:
It means to experience difficulty or struggle when attempting to do a specific action. For example:
She has trouble (in) understanding accents.
They had trouble (in) finding a parking spot.
2. Grammar Notes:
"In" is optional. Modern English often drops the preposition:
✅ I have trouble sleeping. (more natural)
✅ I have trouble in sleeping. (less common but grammatically correct).
Use with nouns: When referring to a noun (not a verb), "in" is typically included:
He has trouble in math class. (not "trouble math class").
3. Common Usage:
Preferred structure: "have trouble + verb-ing" (without "in"):
They have trouble communicating.
Do you have trouble concentrating?
Avoid overcomplicating: Non-native speakers sometimes add unnecessary prepositions. Stick to the simpler form unless emphasizing the context (e.g., formal writing).
4. Examples for Clarity:
Natural: “Many people have trouble public speaking.”
With "in": “She had trouble in adapting to the new rules.” (less frequent).
With a noun: “He has trouble in his job.”
5. Why Confusion Occurs:
Direct translations from other languages (e.g., Spanish "tener problemas para...") might include prepositions like "for" or "in," but English simplifies this.
Key Takeaway:
Use "have trouble + verb-ing" for simplicity and naturalness. Reserve "in" for noun contexts (e.g., trouble in relationships).