在Fragment.onCreateView()中膨胀异常

时间:2014-09-23 07:58:39

标签: android

我的应用程序运行正常,但是当我的家庭活动(包含带有片段的viewpager)经常恢复时,我的应用程序就会被以下logcat输出崩溃:

09-23 11:56:00.110: E/AndroidRuntime(24508): FATAL EXCEPTION: main
09-23 11:56:00.110: E/AndroidRuntime(24508): Process: com.kbazaar, PID: 24508
09-23 11:56:00.110: E/AndroidRuntime(24508): android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at com.kbazaar.view.SwipeableImagesFragmnt.onCreateView(SwipeableImagesFragmnt.java:70)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1226)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.ScrollView.onMeasure(ScrollView.java:326)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5137)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.View.measure(View.java:16540)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1942)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1132)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1321)
09-23 11:56:00.110: E/AndroidRuntime(24508):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)

- SwipeableImagesFragment.java

package com.kbazaar.view;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.androidquery.callback.AjaxStatus;
import com.androidquery.callback.BitmapAjaxCallback;
import com.kbazaar.R;
import com.kbazaar.Utills.MyLog;
import com.kbazaar.datamodel.CategoryOnBanner_DataModel;
import com.kbazaar.datamodel.ImageForCatOnBannerModel;
import com.kbazaar.datamodel.ProductCatModel;

public final class SwipeableImagesFragmnt extends Fragment {
    private static final String KEY_POSITION = "TestFragment:Content";
    int position;
    private static String DATA;
    ArrayList<ImageForCatOnBannerModel> catImagesList;
    ProgressBar progress;
    String catId;
    ImageView playVideo_icon;

     CategoryOnBanner_DataModel objProductCatModel;

    public static SwipeableImagesFragmnt newInstance(
            ArrayList<ImageForCatOnBannerModel> arr, int pos,
            CategoryOnBanner_DataModel objProductCatModel) {
        SwipeableImagesFragmnt fragment = new SwipeableImagesFragmnt();

        fragment.catImagesList = arr;
        fragment.position = pos;
        fragment.objProductCatModel = objProductCatModel;
        return fragment;
    }

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

        if ((savedInstanceState != null)
                && savedInstanceState.containsKey(KEY_POSITION)
                && savedInstanceState.containsKey(DATA)) {
            position = savedInstanceState.getInt(KEY_POSITION);
            catImagesList = (ArrayList<ImageForCatOnBannerModel>) savedInstanceState
                    .getSerializable(DATA);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.vwpager_row, container, false);   // line 70

        ImageView imgVw = (ImageView) view.findViewById(R.id.imgVwforPager);

        progress = (ProgressBar) view.findViewById(R.id.progress);
        playVideo_icon = (ImageView) view.findViewById(R.id.video_icon);

        WindowManager wm = (WindowManager)getActivity().getSystemService(
                Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        int width = metrics.widthPixels;
        int height = metrics.heightPixels;

        imgVw.getLayoutParams().height = height / 4;
        imgVw.getLayoutParams().width = width;

        if(catImagesList.get(position).getImage()!=null){
        AQuery aq = new AQuery(view);

        aq.id(imgVw)
                .progress(progress)
                .image(catImagesList.get(position).getImage(), true, true, 0,
                        R.drawable.defaultnoti, new BitmapAjaxCallback() {
                            @Override
                            public void callback(String url, ImageView iv,
                                    Bitmap bm, AjaxStatus status) {
                                iv.setImageBitmap(bm);
                                progress.setVisibility(View.GONE);

                            }
                        });
        }else {
            imgVw.setImageResource(R.drawable.default_image);
        }



        imgVw.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {

                    if (objProductCatModel.getSubCat() != null
                            && objProductCatModel.getSubCat().size() != 0) {

                        ProductCatModel catModel = new ProductCatModel();
                        catModel.setCategoryId(objProductCatModel
                                .getCategoryId());
                        catModel.setCategoryName(objProductCatModel
                                .getCategoryName());
                        catModel.setSubCat(objProductCatModel.getSubCat());

                        ActivityCategoryNext catfragmnt = new ActivityCategoryNext();

                        Bundle bundle = new Bundle();
                        bundle.putSerializable("obj", catModel);
                        String str = objProductCatModel
                                .getImagedata().get(position).getIndex();
                        if (objProductCatModel
                                .getImagedata().get(position).getIndex()!=null) {
                            bundle.putInt("position", Integer.parseInt(objProductCatModel
                                    .getImagedata().get(position).getIndex()));

                        }
                        else
                        bundle.putInt("position",0);
                        catfragmnt.setArguments(bundle);

                        FragmentTransaction fragmentTransaction = getFragmentManager()
                                .beginTransaction();

                        fragmentTransaction.replace(R.id.content_frame,
                                catfragmnt, "catfragmnt");
                        fragmentTransaction.addToBackStack("catfragmnt");
                        fragmentTransaction.commit();

                    } else {
                        Toast.makeText(
                                getActivity(),
                                getActivity().getResources().getString(
                                        R.string.data_not_found),
                                Toast.LENGTH_LONG).show();

                    }

                } catch (Exception e) {

                    MyLog.e("Swipeable fragmnt", e.toString());
                }

            }
        });


        if (catImagesList.get(position).getMediaurl()!=null && catImagesList.get(position).getMediaurl().trim().length()>0)
            playVideo_icon.setVisibility(android.view.View.VISIBLE);
        else
            playVideo_icon.setVisibility(android.view.View.GONE);
        playVideo_icon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    Intent intent = new Intent(getActivity(), MediaActivity.class);

                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(
                            "mediaurl", catImagesList.get(position).getMediaurl());


                    getActivity().startActivity(intent);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });


        return view;

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(KEY_POSITION, position);
        outState.putSerializable(DATA, catImagesList);
    }
}

0 个答案:

没有答案