Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

android - Fragment is not support in my project

my android studio project is not support fragment class in old project.but new project is will be supported.the app run time android.view.InflateException Exception displayed.how to created fragment in my project?give me any solution.

09-12 10:26:31.066    7892-7892/com.sentientit.theiWedplanner E/AndroidRuntime? FATAL EXCEPTION: main
    Process: com.sentientit.theiWedplanner, PID: 7892
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sentientit.theiWedplanner/com.sentientit.theiWedplanner.Frontpage}: android.view.InflateException: Binary XML file line #11: 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 #11: 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)

------------------------------------------------------------------------

my fragment java class

public class Fragadmob extends Fragment {
    @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;
    }


}

fragment 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="xxxxxxxxxxxxxxx"
         />

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

 </RelativeLayout>

this is my mainactivity 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"
  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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",

Make sure your Fragadmob under the package com.sentientit.theiWedplanner.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...