包含片段时的android.view.InflateException

时间:2015-09-22 09:38:42

标签: android

我的项目不支持片段。它显示android.view.InflateException

我试图创建新的片段类不受支持。显示相同的错误。我创建了包含片段类的新项目。同时我尝试了旧的项目类是复制过去然后运行应用程序工作。那么如何解决这个问题...

错误:

09-22 14:53:00.231    5492-5492/com.sentientit.theiWedplanner E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.sentientit.theiWedplanner, PID: 5492
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sentientit.theiWedplanner/com.sentientit.theiWedplanner.Frontpage}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
            at android.app.Activity.setContentView(Activity.java:1948)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5343)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2323)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.sentientit.theiWedplanner.Fragadmob: make sure class name exists, is public, and has an empty constructor that is public
            at android.app.Fragment.instantiate(Fragment.java:597)
            at android.app.Fragment.instantiate(Fragment.java:561)
            at android.app.Activity.onCreateView(Activity.java:4841)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
            at android.app.Activity.setContentView(Activity.java:1948)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5343)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2323)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sentientit.theiWedplanner.Fragadmob" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.sentientit.theiWedplanner-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.sentientit.theiWedplanner-1, /vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
            at android.app.Fragment.instantiate(Fragment.java:583)
            at android.app.Fragment.instantiate(Fragment.java:561)
            at android.app.Activity.onCreateView(Activity.java:4841)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
            at android.app.Activity.setContentView(Activity.java:1948)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5343)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2323)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2411)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5323)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)

片段xml:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
     android:id="@+id/adview153613"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:background="@drawable/aagr_background2" >

    <ImageView        
              android:id="@+id/image123"
              android:layout_width="fill_parent"
              android:layout_height="50dp"                    
              android:src="@drawable/adview1536132" />

      <com.google.android.gms.ads.AdView
       android:id="@+id/adView"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       ads:adSize="SMART_BANNER"
       ads:adUnitId="xxxxxxxxxxxxxx"
         />

      <ImageView
          android:id="@+id/addviewimage1"
          android:layout_width="31dp"
          android:layout_height="67dp"
          android:layout_alignParentRight="true"
          android:layout_marginRight="23dp"
          android:src="@drawable/close" />

 </RelativeLayout>

片段Java类:

package com.sentientit.theiWedplanner;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
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.ImageView;
import android.widget.RelativeLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class Fragadmob extends Fragment  {
    public Fragadmob() {
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragadmob, container,   false);

        //Admob        
         RelativeLayout gonad=(RelativeLayout)rootView.findViewById(R.id.adview153613);
         ImageView addviewimage=(ImageView)rootView.findViewById(R.id.image123);
         ImageView inap=(ImageView)rootView.findViewById(R.id.addviewimage1);

         //   AdView adView = new AdView(getActivity());
           AdView adView = (AdView)rootView.findViewById(R.id.adView);
          AdRequest adRequest = new AdRequest.Builder().build();
          adView.loadAd(adRequest);
         addviewimage.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                 Intent viewIntent =
                          new Intent("android.intent.action.VIEW",
                            Uri.parse("https://play.google.com/store/apps/developer?id=SentientIT+America,+LLC"));
                          startActivity(viewIntent);

            }

         });
         inap.setOnClickListener(new OnClickListener(){

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                     Intent intent = new Intent(getActivity(),Inapp.class);
                     startActivity(intent);

                }

             });

          if(addviewimage.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
             addviewimage.getLayoutParams().height = 30;
                // code to do for Portrait Mode
            }
          SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
            boolean isPurchase = preferences.getBoolean("isPurchase",false);
  if(isPurchase){

       gonad.setVisibility(View.GONE); //work
  }
        return rootView;
    }


}

主要java类;

package com.sentientit.theiWedplanner;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;

import com.bugsense.trace.BugSenseHandler;
import com.google.android.gms.ads.AdView;

public class Frontpage extends FragmentActivity {
    /** Called when the activity is first created. */
    SharedPreferences sharedPreferences;

    @Override
      public void onStart() {
        super.onStart();
       // The rest of your onStart() code.

        // //  EasyTracker.getInstance(this).activityStart(this);  // Add this method.

      }

      @Override
      public void onStop() {
        super.onStop();

      }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       BugSenseHandler.initAndStartSession(this, "68640bea");
        //requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(R.layout.front);





    }

    }

主Xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">
    <fragment
        android:id="@+id/adview153613"
        android:name="com.sentientit.theiWedplanner.Fragadmob"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout="@layout/fragadmob" />

         <RelativeLayout
             android:id="@+id/fron"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent" >

             <TextView
                 android:id="@+id/textView2"
                 android:layout_width="fill_parent"
                 android:layout_height="50px"
                 android:background="#003399"
                 android:gravity="center"
                 android:text="iWedPlanner"
                 android:textSize="20sp"
                 android:textStyle="bold"
                 android:typeface="serif" />

             <ImageView
                 android:id="@+id/cl"
                 android:layout_width="match_parent"
                 android:layout_height="600dp"
                 android:layout_alignParentLeft="true"
                 android:layout_below="@+id/textView1"
                 android:src="@drawable/ilogo" />

             <TextView
                 android:id="@+id/textView1"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignParentLeft="true"
                 android:layout_below="@+id/textView2"
                 android:layout_marginTop="23dp"
                 android:gravity="center"
                 android:text="Welcome to iWedPlanner"
                 android:textColor="#FF9933"
                 android:textSize="20sp"
                 android:textStyle="italic"
                 android:typeface="serif" />

             <TextView
                 android:id="@+id/textView3"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignBottom="@+id/cl"
                 android:layout_alignParentLeft="true"
                 android:gravity="center"
                 android:text="Your Guide to fun and flawless wedding planning"
                 android:textColor="#FFFF0000"
                 android:textStyle="italic"
                 android:typeface="serif" />

             <ImageButton
                 android:id="@+id/click"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_below="@+id/cl"
                 android:layout_centerHorizontal="true"
                 android:layout_marginTop="40dp"
                 android:background="#FFFFFF"
                 android:src="@drawable/ib" />

         </RelativeLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

你在&#34; Main&#34;中有错误布局xml。尝试替换

<fragment

<Fragment

或者,甚至更好:

<android.support.v4.app.Fragment

你也在做

AdView adview=(AdView)findViewById(R.id.ad);

但我看不到那样的ID(+ @ id / ad)