在Manifest中包含特定的Java文件时发生碎片错误

时间:2015-10-05 05:19:57

标签: java android android-layout android-fragments

我的应用程序停止,同时在manifest.xml中包含特定的java类,并且logcat在fragment中显示错误。如果我从manifest.xml中删除这些类,则应用程序正在成功运行。另一方面,剩下的java类正常工作并且在那里碎片中没有错误。我不知道为什么应用程序因特定的java文件而被停止

这是logcat在包含特定java类

时显示的错误
10-05 10:46:31.617  12820-12820/com.sentientit.theiWedplanner E/AndroidRuntime﹕ FATAL EXCEPTION: main
    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:2245)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.access$700(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:175)
            at android.app.ActivityThread.main(ActivityThread.java:5279)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            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:710)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
            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:350)
            at android.app.Activity.setContentView(Activity.java:1930)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5283)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.access$700(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:175)
            at android.app.ActivityThread.main(ActivityThread.java:5279)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            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:592)
            at android.app.Fragment.instantiate(Fragment.java:560)
            at android.app.Activity.onCreateView(Activity.java:4864)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
            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:350)
            at android.app.Activity.setContentView(Activity.java:1930)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5283)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.access$700(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:175)
            at android.app.ActivityThread.main(ActivityThread.java:5279)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sentientit.theiWedplanner.Fragadmob" on path: /system/framework/com.google.android.maps.jar:/data/app/com.sentientit.theiWedplanner-1.apk
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at android.app.Fragment.instantiate(Fragment.java:582)
            at android.app.Fragment.instantiate(Fragment.java:560)
            at android.app.Activity.onCreateView(Activity.java:4864)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
            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:350)
            at android.app.Activity.setContentView(Activity.java:1930)
            at com.sentientit.theiWedplanner.Frontpage.onCreate(Frontpage.java:41)
            at android.app.Activity.performCreate(Activity.java:5283)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.access$700(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:175)
            at android.app.ActivityThread.main(ActivityThread.java:5279)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
10-05 10:46:40.273  12820-12824/com.sentientit.theiWedplanner D/dalvikvm﹕ GC_CONCURRENT freed 413K, 28% free 6025K/8348K, paused 4ms+2ms, total 36ms

front.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    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>

fragadmob.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="XXXXXXXXXXXXXXXXXXXXXXXXXXX"
         />
       <ImageView
          android:id="@+id/addviewimage1"
          android:layout_width="31dp"
          android:layout_height="31dp"
          android:layout_alignParentRight="true"
          android:layout_marginRight="23dp"
          android:src="@drawable/close" />
 </RelativeLayout>

frontpage.java

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;

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();
        // The rest of your onStop() code.

        // EasyTracker.getInstance(this).activityStop(this);  // Add this method.
      }


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

        setContentView(R.layout.front);


      RelativeLayout clic =(RelativeLayout)findViewById(R.id.fron);
       clic.setOnClickListener(new OnClickListener() {

            //@Override
            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                Intent intent=new Intent(Frontpage.this,welcomeuser1.class);
                //Intent intent=new Intent(Frontpage.this,ZXingJarDemoActivity.class);
                startActivity(intent);
                finish();
            }



    });



    }

    }

fragadmob.java

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  {

    @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);



          if(addviewimage.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
             addviewimage.getLayoutParams().height = 30;
                // code to do for Portrait Mode
            }

        return rootView;
    }


}

1 个答案:

答案 0 :(得分:0)

您永远不需要在清单中添加片段。你的logcat显示ClassNotFoundException: Didn't find class "com.sentientit.theiWedplanner.Fragadmob"但是Fragadmob扩展了Fragment所以你试图在showast中添加片段,所以一定要确保编码。