java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.app.AdvertListActivity}: android.view.InflateException: Binary XML file line #7: Class is not a View android.support.v4.app.Fragment

tip
Do you find the tips below useful? Click on the to mark them and say thanks to rafael and Rafael Fischer Viola . Or join the community to write better ones.
  1. 0
    samebug tip
    As of SDK 23, you have to call this method with ContextCompat.getColor(context, R.color.my_color) so it works with previous API as well. Also, you have to add the support V4 library to your dependencies: "compile 'com.android.support:support-v4:23.0.1'"
  2. 0
    samebug tip
    When you use findViewById inside an activity it is going to look for a View inside your main_activity.xml. If it's not there, it throws this exception, try to use the right view to call findviewById.
  3. 0
    samebug tip
    Check if you imported android.support.v4.app.FragmentManager and not android.app.FragmentManager. Check for naming problems in your xml files as well, might have inconsistencies!
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    samebug tip
    Also, check if you're not using android.support.v4.app.FragmentTransaction with android.app.Fragment, as they're not totally compatible.
  6. 0
    samebug tip
    If you're using nested fragments, you have to use childFragmentManager instead of fragmentManager.

  1. maxxi 4 times, last 8 months ago
  2. Hronom 16 times, last 4 months ago
8 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.ClassCastException

    android.support.v4.app.Fragment cannot be cast to android.view.View

    at java.lang.Class.asSubclass()
  2. Java RT
    Class.asSubclass
    1. java.lang.Class.asSubclass(Class.java:1380)
    1 frame
  3. Android Platform
    LayoutInflater.inflate
    1. android.view.LayoutInflater.createView(LayoutInflater.java:552)
    2. android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
    3. android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    4. android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    5. android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    6. android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    6 frames
  4. Android
    PhoneWindow.setContentView
    1. com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
    1 frame
  5. Android Platform
    Activity.setContentView
    1. android.app.Activity.setContentView(Activity.java:1881)
    1 frame
  6. com.myapp.app
    AdvertListActivity.onCreate
    1. com.myapp.app.AdvertListActivity.onCreate(AdvertListActivity.java:19)
    1 frame
  7. Android Platform
    ActivityThread.main
    1. android.app.Activity.performCreate(Activity.java:5104)
    2. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    3. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    4. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    5. android.app.ActivityThread.access$600(ActivityThread.java:141)
    6. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    7. android.os.Handler.dispatchMessage(Handler.java:99)
    8. android.os.Looper.loop(Looper.java:137)
    9. android.app.ActivityThread.main(ActivityThread.java:5041)
    9 frames
  8. Java RT
    Method.invoke
    1. java.lang.reflect.Method.invokeNative(Native Method)
    2. java.lang.reflect.Method.invoke(Method.java:511)
    2 frames
  9. Android
    ZygoteInit.main
    1. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    2. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    2 frames
  10. Android Platform
    NativeStart.main
    1. dalvik.system.NativeStart.main(Native Method)
    1 frame