Android App Crashes When Adding Layout Containing Fragment


I am trying to impliment the simple example here in Android Studio:

The problem is the app crashes as soon as I try and add the layout to the activity. If I take the fragment out of the activity, it adds fine. 


IT doesn’t really throw an exception, it just “quits”. This is what is in the log. 

11:17:42 AM CalledFromWrongThreadException

            Access is allowed from event dispatch thread only.

            Details: EventQueue.isDispatchThread()=false



            Current thread: Thread[ApplicationImpl pooled thread 28,4,main] 1955286092

            SystemEventQueueThread: Thread[AWT-EventQueue-1 1.5#AI-141.2422023, eap:false,6,main] 554087786

            “AWT-EventQueue-1 1.5#AI-141.2422023, eap:false” prio=0 tid=0x0 nid=0x0 waiting on condition

            java.lang.Thread.State: WAITING

            on com.intellij.ide.IdeEventQueue@27a05dcf

            at java.lang.Object.wait(Native Method)

            at java.lang.Object.wait(

            at java.awt.EventQueue.getNextEvent(

            at java.awt.EventDispatchThread.pumpOneEventForFilters(

            at java.awt.EventDispatchThread.pumpEventsForFilter(

            at java.awt.EventDispatchThread.pumpEventsForHierarchy(

            at java.awt.EventDispatchThread.pumpEvents(… (show balloon)

In the variables, this equals:


Thanks for any help



Can you please tell us a little more about your environment? What OS are you developing on? I am assuming you are using Android Studio - if so which version of this are you using? Also, what JDK are you using? I am not familiar with this exception which you are getting but my initial research suggests it may be related to the environment (for example version of Android Studio).

Please advise.