1

i have create an Activity with 2 seprat Fragments. In the Run Time the error are these:

Here is the code:

<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

    <fragment    
        android:name="com.example.lesson1.Fragment1"
        android:id="@+id/activity_fragment1"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent"
     />

    <fragment 
        android:name="com.example.lesson1.Fragment2"
        android:id="@+id/activity_fragment2"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent"
     />


</LinearLayout>

public class Myfragments extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_myfragments);

    }
}

The errors are :

03-26 11:26:27.808: E/Trace(5610): error opening trace file: No such file or directory (2)
03-26 11:26:31.780: E/AndroidRuntime(5610): FATAL EXCEPTION: main
03-26 11:26:31.780: E/AndroidRuntime(5610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lesson1/com.example.lesson1.Myfragments}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.os.Looper.loop(Looper.java:137)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.app.ActivityThread.main(ActivityThread.java:4745)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at java.lang.reflect.Method.invokeNative(Native Method)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at java.lang.reflect.Method.invoke(Method.java:511)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at dalvik.system.NativeStart.main(Native Method)
03-26 11:26:31.780: E/AndroidRuntime(5610): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-26 11:26:31.780: E/AndroidRuntime(5610):     at 
.
.
.
7
  • 2
    Check you imports once Fragment and FragmentActivity are from the support library or not. Commented Mar 26, 2014 at 11:38
  • You extend Activity so you should not have imports from the support library Commented Mar 26, 2014 at 11:42
  • @kalyanpvs my adds are import 'android.support.v4.app.Fragment;' Commented Mar 26, 2014 at 11:46
  • @Salman that is no nedded import android.app.Fragment Commented Mar 26, 2014 at 11:47
  • 1
    @Salman you need to extend FragmentActivity instead of Activity Commented Mar 26, 2014 at 11:47

1 Answer 1

2

my adds are import 'android.support.v4.app.Fragment

You extend Normal Activity. So you need to use import android.app.Fragment.

If you want to use Fragment from Support Library then extend FragmentActivity and use import android.support.v4.app.Fragment.

Fragment Activity is the base class for SupportBased Fragments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.