0

I am trying to start a new activity from within a nested fragment using the following code :

Intent rateIntent = new Intent(context, RateServiceActivity.class);
getActivity().startActivity(rateIntent);

I am getting the following error :

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.serve.learn/com.serve.learn.MyOrdersPage.RateServiceActivity}: 
android.view.InflateException: Binary XML file line #31: Error inflating class fragment

I have tried all the solutions provided online with no luck. Also, I think this error is specific to nested fragments scenario for me and not the generic errors mentioned in other posts.

There shouldn't be any issues with my xml files because I did not face any issues till now. Only when I am trying to start a new activity from within a nested fragment I am getting this error.

Anyway, this is code in my activity_main.xml (starting from line #31) :

<fragment
    android:id="@+id/navigation_drawer"
    android:name="com.serve.learn.MainActivityPage.NavigationDrawerFragment"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    tools:layout="@layout/fragment_navigation_drawer" />

Here is the nested fragment code :

package com.serve.learn.MyOrdersPage;

import com.serve.learn.R;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class Fragment_Fragment_UpcomingOrders extends Fragment implements OnClickListener{

    TextView order1Details, order1, order2Details, order2, order3Details, order3;
    View rootView;
    Button callButton, rateButton;
    Context context;

     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            rootView = inflater.inflate(R.layout.fragment_fragment_upcoming_orders, container, false);
            context = rootView.getContext();
            order1Details = (TextView) rootView.findViewById(R.id.order1Details);
            order1Details.setVisibility(View.GONE);
            order1 = (TextView) rootView.findViewById(R.id.order1);
            order1.setOnClickListener(this);
            order2Details = (TextView) rootView.findViewById(R.id.order2Details);
            order2Details.setVisibility(View.GONE);
            order2 = (TextView) rootView.findViewById(R.id.order2);
            order2.setOnClickListener(this);
            order3Details = (TextView) rootView.findViewById(R.id.order3Details);
            order3Details.setVisibility(View.GONE);
            order3 = (TextView) rootView.findViewById(R.id.order3);
            order3.setOnClickListener(this);
            callButton = (Button) rootView.findViewById(R.id.callButton);
            callButton.setOnClickListener(this);
            rateButton = (Button) rootView.findViewById(R.id.rateButton);
            rateButton.setOnClickListener(this);
            return rootView;
        }

     @Override
    public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
     }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId())
        {
        case R.id.order1 :  order1Details.setVisibility( order1Details.isShown()? View.GONE:View.VISIBLE );
                            break;
        case R.id.order2 :  order2Details.setVisibility( order2Details.isShown()? View.GONE:View.VISIBLE );
                            break;
        case R.id.order3 :  order3Details.setVisibility( order3Details.isShown()? View.GONE:View.VISIBLE );
                            break;
        case R.id.callButton :  Intent callIntent = new Intent(Intent.ACTION_CALL);
                                callIntent.setData(Uri.parse("tel:123456789"));
                                startActivity(callIntent);
                                break;
        case R.id.rateButton :  Intent rateIntent = new Intent(context, RateServiceActivity.class);
                                getActivity().startActivity(rateIntent);
                                break;
        }
    }
}

Code for fragment_fragment_upcoming_orders.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:layout_gravity="center_vertical|center_horizontal" >

<!-- activity_info layout file -->
<!-- Clickable title -->

<TextView
    android:id="@+id/order1"
    android:layout_width="179dp"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:text="@string/Order1" />

    <!--content to hide/show -->

<TextView
    android:id="@+id/order1Details"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:text="@string/Order1Details" />

<TextView
    android:id="@+id/order2"
    android:layout_width="179dp"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:text="@string/Order2" />

<TextView
    android:id="@+id/order2Details"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:text="@string/Order2Details" />

<TextView
    android:id="@+id/order3"
    android:layout_width="179dp"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:text="@string/Order3" />

<TextView
    android:id="@+id/order3Details"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:text="@string/Order3Details" />

<Button
    android:id="@+id/callButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Call" />

<Button
    android:id="@+id/rateButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rate" />

</LinearLayout>

Any suggestions as to where I might be going wrong?

Jin Lee
  • 3,194
  • 12
  • 46
  • 86

0 Answers0