首页 \ 问答 \ Logcat错误:无法在android片段中加载视图(Logcat error: unable to load view in android fragments)

Logcat错误:无法在android片段中加载视图(Logcat error: unable to load view in android fragments)

我试图从活动切换到片段。 我确实认为我的代码是正确的。 但我仍然在logcat中收到错误,它无法加载视图。 请告诉我我错在哪里。

我的LOGCAT:

10-01 14:53:58.314: E/FragmentManager(1048): No view found for id 0x7f090001 (com.example.test:id/content_frame) for fragment WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.314: E/FragmentManager(1048): Activity state:
10-01 14:53:58.324: E/FragmentManager(1048):   Local Activity 4184bfe0 State:
10-01 14:53:58.334: E/FragmentManager(1048):     mResumed=true mStopped=false mFinished=false
10-01 14:53:58.344: E/FragmentManager(1048):     mLoadersStarted=true
10-01 14:53:58.344: E/FragmentManager(1048):     mChangingConfigurations=false
10-01 14:53:58.355: E/FragmentManager(1048):     mCurrentConfig={1.0 310mcc260mnc en_US ldltr sw320dp w320dp h508dp 240dpi nrml long port finger qwerty/v/v -nav/h s.6}
10-01 14:53:58.355: E/FragmentManager(1048):   Active Fragments in 4184c110:
10-01 14:53:58.364: E/FragmentManager(1048):     #0: WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.364: E/FragmentManager(1048):       mFragmentId=#7f090001 mContainerId=#7f090001 mTag=null
10-01 14:53:58.374: E/FragmentManager(1048):       mState=0 mIndex=0 mWho=android:fragment:0 mBackStackNesting=1
10-01 14:53:58.374: E/FragmentManager(1048):       mAdded=true mRemoving=false mResumed=false mFromLayout=false mInLayout=false
10-01 14:53:58.384: E/FragmentManager(1048):       mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
10-01 14:53:58.394: E/FragmentManager(1048):       mRetainInstance=false mRetaining=false mUserVisibleHint=true
10-01 14:53:58.405: E/FragmentManager(1048):       mFragmentManager=FragmentManager{4184c110 in Home{4184bfe0}}
10-01 14:53:58.414: E/FragmentManager(1048):       mActivity=com.example.test.Home@4184bfe0
10-01 14:53:58.414: E/FragmentManager(1048):   Added Fragments:
10-01 14:53:58.425: E/FragmentManager(1048):     #0: WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.425: E/FragmentManager(1048):   Back Stack Indices:
10-01 14:53:58.425: E/FragmentManager(1048):     #0: BackStackEntry{418ae440 #0}
10-01 14:53:58.434: E/FragmentManager(1048):   FragmentManager misc state:
10-01 14:53:58.434: E/FragmentManager(1048):     mActivity=com.example.test.Home@4184bfe0
10-01 14:53:58.444: E/FragmentManager(1048):     mContainer=android.app.Activity$1@4184c188
10-01 14:53:58.455: E/FragmentManager(1048):     mCurState=5 mStateSaved=false mDestroyed=false
10-01 14:53:58.455: E/FragmentManager(1048):   View Hierarchy:
10-01 14:53:58.455: E/FragmentManager(1048):     com.android.internal.policy.impl.PhoneWindow$DecorView{4184cca8 V.E..... R.....ID 0,0-480,800}
10-01 14:53:58.474: E/FragmentManager(1048):       com.android.internal.widget.ActionBarOverlayLayout{4184d3c8 V.E..... ......ID 0,0-480,800 #102033d android:id/action_bar_overlay_layout}
10-01 14:53:58.474: E/FragmentManager(1048):         android.widget.FrameLayout{4184e038 V.E..... ......ID 0,110-480,800 #1020002 android:id/content}
10-01 14:53:58.484: E/FragmentManager(1048):           android.widget.RelativeLayout{41856d18 V.E..... ......ID 0,0-480,690}
10-01 14:53:58.495: E/FragmentManager(1048):             android.widget.TableLayout{41857488 V.E..... ......I. 24,333-456,666 #7f09000d app:id/tableLayout1}
10-01 14:53:58.495: E/FragmentManager(1048):               android.widget.TableRow{41857c78 V.E..... ......I. 0,0-432,87 #7f09000e app:id/tableRow1}
10-01 14:53:58.504: E/FragmentManager(1048):                 android.widget.Button{418581b8 VFED..C. ......I. 0,0-208,72 #7f090018 app:id/button1}
10-01 14:53:58.514: E/FragmentManager(1048):                 android.widget.Button{41864768 VFED..C. ......I. 223,0-432,72 #7f090019 app:id/button2}
10-01 14:53:58.514: E/FragmentManager(1048):               android.widget.TableRow{41864d30 V.E..... ......I. 0,87-432,174 #7f090010 app:id/tableRow2}
10-01 14:53:58.524: E/FragmentManager(1048):                 android.widget.Button{41865108 VFED..C. ......I. 0,0-208,72 #7f09001a app:id/button3}
10-01 14:53:58.535: E/FragmentManager(1048):                 android.widget.Button{418656c8 VFED..C. ......I. 223,0-432,72 #7f09001b app:id/button4}
10-01 14:53:58.535: E/FragmentManager(1048):               android.widget.TableRow{41865c88 V.E..... ......I. 0,174-432,246 #7f090012 app:id/tableRow3}
10-01 14:53:58.544: E/FragmentManager(1048):                 android.widget.Button{41866060 VFED..C. ......I. 0,0-208,72 #7f09001c app:id/button5}
10-01 14:53:58.544: E/FragmentManager(1048):                 android.widget.Button{41866630 VFED..C. ......I. 223,0-432,72 #7f09001d app:id/button6}
10-01 14:53:58.544: E/FragmentManager(1048):               android.widget.TableRow{41866be8 V.E..... ......I. 0,261-432,333 #7f090014 app:id/tableRow4}
10-01 14:53:58.554: E/FragmentManager(1048):                 android.widget.Button{41866fc0 VFED..C. ......I. 0,0-208,72 #7f09001e app:id/button7}
10-01 14:53:58.554: E/FragmentManager(1048):                 android.widget.Button{41867580 VFED..C. ......I. 223,0-432,72 #7f09001f app:id/button8}
10-01 14:53:58.564: E/FragmentManager(1048):             android.widget.ImageView{41867b88 V.ED.... ......I. 24,24-456,99 #7f090003 app:id/imageView1}
10-01 14:53:58.564: E/FragmentManager(1048):             android.widget.ScrollView{4173e9d0 VFED.V.. ......ID 24,99-456,306 #7f090020 app:id/ScrollView01}
10-01 14:53:58.574: E/FragmentManager(1048):               android.widget.RelativeLayout{41773b10 V.E..... ......ID 0,0-432,174 #7f090021 app:id/RelativeLayout01}
10-01 14:53:58.574: E/FragmentManager(1048):                 android.widget.LinearLayout{41776658 V.E..... ......ID 0,0-432,174 #7f090022 app:id/LinearLayout01}
10-01 14:53:58.574: E/FragmentManager(1048):                   android.widget.TextView{41747670 V.ED.... ......I. 172,0-259,29 #7f090004 app:id/textView1}
10-01 14:53:58.584: E/FragmentManager(1048):                   android.widget.TextView{41758a38 V.ED.... ......I. 172,29-259,58 #7f090005 app:id/textView2}
10-01 14:53:58.584: E/FragmentManager(1048):                   android.widget.TextView{417538a0 V.ED.... ......I. 172,58-259,87 #7f090008 app:id/textView3}
10-01 14:53:58.594: E/FragmentManager(1048):                   android.widget.TextView{41753b40 V.ED.... ......I. 172,87-259,116 #7f090007 app:id/textView4}
10-01 14:53:58.604: E/FragmentManager(1048):                   android.widget.TextView{41850368 V.ED.... ......I. 172,116-259,145 #7f090006 app:id/textView5}
10-01 14:53:58.614: E/FragmentManager(1048):                   android.widget.TextView{41850608 V.ED.... ......I. 172,145-259,174 #7f090009 app:id/textView6}
10-01 14:53:58.614: E/FragmentManager(1048):         android.widget.LinearLayout{4184e490 V.E..... ......I. 0,38-480,110 #102033e android:id/top_action_bar}
10-01 14:53:58.624: E/FragmentManager(1048):           com.android.internal.widget.ActionBarContainer{4184e8c8 V.ED.... ......I. 0,0-480,72 #102033f android:id/action_bar_container}
10-01 14:53:58.624: E/FragmentManager(1048):             com.android.internal.widget.ActionBarView{4184eeb0 V.E..... ......I. 0,0-480,72 #1020340 android:id/action_bar}
10-01 14:53:58.634: E/FragmentManager(1048):               android.widget.LinearLayout{41850090 V.....C. ......I. 13,0-131,72}
10-01 14:53:58.634: E/FragmentManager(1048):                 com.android.internal.widget.ActionBarView$HomeView{41851798 V.E..... ......I. 0,0-60,72}
10-01 14:53:58.644: E/FragmentManager(1048):                   android.widget.ImageView{41851c08 G.ED.... ......I. 0,0-0,0 #1020252 android:id/up}
10-01 14:53:58.655: E/FragmentManager(1048):                   android.widget.ImageView{41851f90 V.ED.... ......I. 6,12-54,60 #102002c android:id/home}
10-01 14:53:58.655: E/FragmentManager(1048):                 android.widget.LinearLayout{418538d8 V.E..... ......I. 60,0-118,72}
10-01 14:53:58.674: E/FragmentManager(1048):                   android.widget.ImageView{41853cc8 G.ED.... ......I. 0,0-0,0 #1020252 android:id/up}
10-01 14:53:58.674: E/FragmentManager(1048):                   android.widget.LinearLayout{41854058 V.E..... ......I. 0,17-46,54}
10-01 14:53:58.684: E/FragmentManager(1048):                     android.widget.TextView{41854450 V.ED.... ......I. 0,0-46,37 #102025a android:id/action_bar_title}
10-01 14:53:58.694: E/FragmentManager(1048):                     android.widget.TextView{41855178 G.ED.... ......I. 0,0-0,0 #102025b android:id/action_bar_subtitle}
10-01 14:53:58.705: E/FragmentManager(1048):               com.android.internal.view.menu.ActionMenuView{418a5e30 V.ED.... ......I. 480,0-480,72}
10-01 14:53:58.714: E/FragmentManager(1048):             com.android.internal.widget.ActionBarContextView{418557b8 G.E..... ......ID 0,0-0,0 #1020341 android:id/action_context_bar}
10-01 14:53:58.714: E/FragmentManager(1048):           android.widget.ImageView{41855d28 V.ED.... ......I. 480,0-480,24}
10-01 14:53:58.734: E/FragmentManager(1048):         com.android.internal.widget.ActionBarContainer{418560a0 G.ED.... ......ID 0,0-0,0 #1020342 android:id/split_action_bar}
10-01 14:53:58.734: D/AndroidRuntime(1048): Shutting down VM
10-01 14:53:58.734: W/dalvikvm(1048): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
10-01 14:53:58.804: E/AndroidRuntime(1048): FATAL EXCEPTION: main
10-01 14:53:58.804: E/AndroidRuntime(1048): java.lang.IllegalArgumentException: No view found for id 0x7f090001 (com.example.test:id/content_frame) for fragment WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:877)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.BackStackRecord.run(BackStackRecord.java:682)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.os.Handler.handleCallback(Handler.java:730)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.os.Looper.loop(Looper.java:137)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at java.lang.reflect.Method.invokeNative(Native Method)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at java.lang.reflect.Method.invoke(Method.java:525)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at dalvik.system.NativeStart.main(Native Method)
10-01 14:54:01.205: I/Process(1048): Sending signal. PID: 1048 SIG: 9

我的活动文件:

package com.example.test;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Home extends Activity implements OnClickListener {
Button btn1;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    FrameLayout frame = (FrameLayout) findViewById(R.id.content_frame);
    btn1 = (Button) findViewById(R.id.button1);
    btn1.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

        Fragment newFragment = new WordFragment();
        FragmentTransaction transaction = getFragmentManager()
                .beginTransaction();
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();

        break;

 }
 }

我的WordFragment类:

package com.example.test;

import android.app.Fragment;
import android.app.FragmentTransaction;   
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class WordFragment extends Fragment {

public WordFragment() {

}

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

    View view = inflater.inflate(R.layout.activity_word, container, false);

    return view;
}
}

I am trying to switch from activity to fragment. I do think so that my code is correct. but i still am getting the error in logcat that it is unable to load the view. Please tell me where i am wrong.

My LOGCAT:

10-01 14:53:58.314: E/FragmentManager(1048): No view found for id 0x7f090001 (com.example.test:id/content_frame) for fragment WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.314: E/FragmentManager(1048): Activity state:
10-01 14:53:58.324: E/FragmentManager(1048):   Local Activity 4184bfe0 State:
10-01 14:53:58.334: E/FragmentManager(1048):     mResumed=true mStopped=false mFinished=false
10-01 14:53:58.344: E/FragmentManager(1048):     mLoadersStarted=true
10-01 14:53:58.344: E/FragmentManager(1048):     mChangingConfigurations=false
10-01 14:53:58.355: E/FragmentManager(1048):     mCurrentConfig={1.0 310mcc260mnc en_US ldltr sw320dp w320dp h508dp 240dpi nrml long port finger qwerty/v/v -nav/h s.6}
10-01 14:53:58.355: E/FragmentManager(1048):   Active Fragments in 4184c110:
10-01 14:53:58.364: E/FragmentManager(1048):     #0: WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.364: E/FragmentManager(1048):       mFragmentId=#7f090001 mContainerId=#7f090001 mTag=null
10-01 14:53:58.374: E/FragmentManager(1048):       mState=0 mIndex=0 mWho=android:fragment:0 mBackStackNesting=1
10-01 14:53:58.374: E/FragmentManager(1048):       mAdded=true mRemoving=false mResumed=false mFromLayout=false mInLayout=false
10-01 14:53:58.384: E/FragmentManager(1048):       mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
10-01 14:53:58.394: E/FragmentManager(1048):       mRetainInstance=false mRetaining=false mUserVisibleHint=true
10-01 14:53:58.405: E/FragmentManager(1048):       mFragmentManager=FragmentManager{4184c110 in Home{4184bfe0}}
10-01 14:53:58.414: E/FragmentManager(1048):       mActivity=com.example.test.Home@4184bfe0
10-01 14:53:58.414: E/FragmentManager(1048):   Added Fragments:
10-01 14:53:58.425: E/FragmentManager(1048):     #0: WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.425: E/FragmentManager(1048):   Back Stack Indices:
10-01 14:53:58.425: E/FragmentManager(1048):     #0: BackStackEntry{418ae440 #0}
10-01 14:53:58.434: E/FragmentManager(1048):   FragmentManager misc state:
10-01 14:53:58.434: E/FragmentManager(1048):     mActivity=com.example.test.Home@4184bfe0
10-01 14:53:58.444: E/FragmentManager(1048):     mContainer=android.app.Activity$1@4184c188
10-01 14:53:58.455: E/FragmentManager(1048):     mCurState=5 mStateSaved=false mDestroyed=false
10-01 14:53:58.455: E/FragmentManager(1048):   View Hierarchy:
10-01 14:53:58.455: E/FragmentManager(1048):     com.android.internal.policy.impl.PhoneWindow$DecorView{4184cca8 V.E..... R.....ID 0,0-480,800}
10-01 14:53:58.474: E/FragmentManager(1048):       com.android.internal.widget.ActionBarOverlayLayout{4184d3c8 V.E..... ......ID 0,0-480,800 #102033d android:id/action_bar_overlay_layout}
10-01 14:53:58.474: E/FragmentManager(1048):         android.widget.FrameLayout{4184e038 V.E..... ......ID 0,110-480,800 #1020002 android:id/content}
10-01 14:53:58.484: E/FragmentManager(1048):           android.widget.RelativeLayout{41856d18 V.E..... ......ID 0,0-480,690}
10-01 14:53:58.495: E/FragmentManager(1048):             android.widget.TableLayout{41857488 V.E..... ......I. 24,333-456,666 #7f09000d app:id/tableLayout1}
10-01 14:53:58.495: E/FragmentManager(1048):               android.widget.TableRow{41857c78 V.E..... ......I. 0,0-432,87 #7f09000e app:id/tableRow1}
10-01 14:53:58.504: E/FragmentManager(1048):                 android.widget.Button{418581b8 VFED..C. ......I. 0,0-208,72 #7f090018 app:id/button1}
10-01 14:53:58.514: E/FragmentManager(1048):                 android.widget.Button{41864768 VFED..C. ......I. 223,0-432,72 #7f090019 app:id/button2}
10-01 14:53:58.514: E/FragmentManager(1048):               android.widget.TableRow{41864d30 V.E..... ......I. 0,87-432,174 #7f090010 app:id/tableRow2}
10-01 14:53:58.524: E/FragmentManager(1048):                 android.widget.Button{41865108 VFED..C. ......I. 0,0-208,72 #7f09001a app:id/button3}
10-01 14:53:58.535: E/FragmentManager(1048):                 android.widget.Button{418656c8 VFED..C. ......I. 223,0-432,72 #7f09001b app:id/button4}
10-01 14:53:58.535: E/FragmentManager(1048):               android.widget.TableRow{41865c88 V.E..... ......I. 0,174-432,246 #7f090012 app:id/tableRow3}
10-01 14:53:58.544: E/FragmentManager(1048):                 android.widget.Button{41866060 VFED..C. ......I. 0,0-208,72 #7f09001c app:id/button5}
10-01 14:53:58.544: E/FragmentManager(1048):                 android.widget.Button{41866630 VFED..C. ......I. 223,0-432,72 #7f09001d app:id/button6}
10-01 14:53:58.544: E/FragmentManager(1048):               android.widget.TableRow{41866be8 V.E..... ......I. 0,261-432,333 #7f090014 app:id/tableRow4}
10-01 14:53:58.554: E/FragmentManager(1048):                 android.widget.Button{41866fc0 VFED..C. ......I. 0,0-208,72 #7f09001e app:id/button7}
10-01 14:53:58.554: E/FragmentManager(1048):                 android.widget.Button{41867580 VFED..C. ......I. 223,0-432,72 #7f09001f app:id/button8}
10-01 14:53:58.564: E/FragmentManager(1048):             android.widget.ImageView{41867b88 V.ED.... ......I. 24,24-456,99 #7f090003 app:id/imageView1}
10-01 14:53:58.564: E/FragmentManager(1048):             android.widget.ScrollView{4173e9d0 VFED.V.. ......ID 24,99-456,306 #7f090020 app:id/ScrollView01}
10-01 14:53:58.574: E/FragmentManager(1048):               android.widget.RelativeLayout{41773b10 V.E..... ......ID 0,0-432,174 #7f090021 app:id/RelativeLayout01}
10-01 14:53:58.574: E/FragmentManager(1048):                 android.widget.LinearLayout{41776658 V.E..... ......ID 0,0-432,174 #7f090022 app:id/LinearLayout01}
10-01 14:53:58.574: E/FragmentManager(1048):                   android.widget.TextView{41747670 V.ED.... ......I. 172,0-259,29 #7f090004 app:id/textView1}
10-01 14:53:58.584: E/FragmentManager(1048):                   android.widget.TextView{41758a38 V.ED.... ......I. 172,29-259,58 #7f090005 app:id/textView2}
10-01 14:53:58.584: E/FragmentManager(1048):                   android.widget.TextView{417538a0 V.ED.... ......I. 172,58-259,87 #7f090008 app:id/textView3}
10-01 14:53:58.594: E/FragmentManager(1048):                   android.widget.TextView{41753b40 V.ED.... ......I. 172,87-259,116 #7f090007 app:id/textView4}
10-01 14:53:58.604: E/FragmentManager(1048):                   android.widget.TextView{41850368 V.ED.... ......I. 172,116-259,145 #7f090006 app:id/textView5}
10-01 14:53:58.614: E/FragmentManager(1048):                   android.widget.TextView{41850608 V.ED.... ......I. 172,145-259,174 #7f090009 app:id/textView6}
10-01 14:53:58.614: E/FragmentManager(1048):         android.widget.LinearLayout{4184e490 V.E..... ......I. 0,38-480,110 #102033e android:id/top_action_bar}
10-01 14:53:58.624: E/FragmentManager(1048):           com.android.internal.widget.ActionBarContainer{4184e8c8 V.ED.... ......I. 0,0-480,72 #102033f android:id/action_bar_container}
10-01 14:53:58.624: E/FragmentManager(1048):             com.android.internal.widget.ActionBarView{4184eeb0 V.E..... ......I. 0,0-480,72 #1020340 android:id/action_bar}
10-01 14:53:58.634: E/FragmentManager(1048):               android.widget.LinearLayout{41850090 V.....C. ......I. 13,0-131,72}
10-01 14:53:58.634: E/FragmentManager(1048):                 com.android.internal.widget.ActionBarView$HomeView{41851798 V.E..... ......I. 0,0-60,72}
10-01 14:53:58.644: E/FragmentManager(1048):                   android.widget.ImageView{41851c08 G.ED.... ......I. 0,0-0,0 #1020252 android:id/up}
10-01 14:53:58.655: E/FragmentManager(1048):                   android.widget.ImageView{41851f90 V.ED.... ......I. 6,12-54,60 #102002c android:id/home}
10-01 14:53:58.655: E/FragmentManager(1048):                 android.widget.LinearLayout{418538d8 V.E..... ......I. 60,0-118,72}
10-01 14:53:58.674: E/FragmentManager(1048):                   android.widget.ImageView{41853cc8 G.ED.... ......I. 0,0-0,0 #1020252 android:id/up}
10-01 14:53:58.674: E/FragmentManager(1048):                   android.widget.LinearLayout{41854058 V.E..... ......I. 0,17-46,54}
10-01 14:53:58.684: E/FragmentManager(1048):                     android.widget.TextView{41854450 V.ED.... ......I. 0,0-46,37 #102025a android:id/action_bar_title}
10-01 14:53:58.694: E/FragmentManager(1048):                     android.widget.TextView{41855178 G.ED.... ......I. 0,0-0,0 #102025b android:id/action_bar_subtitle}
10-01 14:53:58.705: E/FragmentManager(1048):               com.android.internal.view.menu.ActionMenuView{418a5e30 V.ED.... ......I. 480,0-480,72}
10-01 14:53:58.714: E/FragmentManager(1048):             com.android.internal.widget.ActionBarContextView{418557b8 G.E..... ......ID 0,0-0,0 #1020341 android:id/action_context_bar}
10-01 14:53:58.714: E/FragmentManager(1048):           android.widget.ImageView{41855d28 V.ED.... ......I. 480,0-480,24}
10-01 14:53:58.734: E/FragmentManager(1048):         com.android.internal.widget.ActionBarContainer{418560a0 G.ED.... ......ID 0,0-0,0 #1020342 android:id/split_action_bar}
10-01 14:53:58.734: D/AndroidRuntime(1048): Shutting down VM
10-01 14:53:58.734: W/dalvikvm(1048): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
10-01 14:53:58.804: E/AndroidRuntime(1048): FATAL EXCEPTION: main
10-01 14:53:58.804: E/AndroidRuntime(1048): java.lang.IllegalArgumentException: No view found for id 0x7f090001 (com.example.test:id/content_frame) for fragment WordFragment{418ae390 #0 id=0x7f090001}
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:877)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.BackStackRecord.run(BackStackRecord.java:682)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.os.Handler.handleCallback(Handler.java:730)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.os.Looper.loop(Looper.java:137)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at java.lang.reflect.Method.invokeNative(Native Method)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at java.lang.reflect.Method.invoke(Method.java:525)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-01 14:53:58.804: E/AndroidRuntime(1048):     at dalvik.system.NativeStart.main(Native Method)
10-01 14:54:01.205: I/Process(1048): Sending signal. PID: 1048 SIG: 9

My Activity File :

package com.example.test;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Home extends Activity implements OnClickListener {
Button btn1;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    FrameLayout frame = (FrameLayout) findViewById(R.id.content_frame);
    btn1 = (Button) findViewById(R.id.button1);
    btn1.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

        Fragment newFragment = new WordFragment();
        FragmentTransaction transaction = getFragmentManager()
                .beginTransaction();
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();

        break;

 }
 }

My WordFragment class:

package com.example.test;

import android.app.Fragment;
import android.app.FragmentTransaction;   
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class WordFragment extends Fragment {

public WordFragment() {

}

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

    View view = inflater.inflate(R.layout.activity_word, container, false);

    return view;
}
}

原文:https://stackoverflow.com/questions/26148890
更新时间:2019-07-12 10:31

最满意答案

当您使用片段事务在onClick中添加WordFragment时,它抱怨它找不到具有用于放置片段的id content_frame的父视图。

检查以确保home.xml布局中有一个id为content_frame的容器作为此片段的父级。


When you add your WordFragment in onClick using the fragment transaction, it is complaining that it can't find a parent view with the id content_frame in which to place your fragment.

Check to make sure your home.xml layout has a container with an id of content_frame to serve as the parent for this fragment.

2014-10-01

相关问答

更多

附加带有文本文件的集合(Appending a set with a text file)

你应该这样做: Set<Integer> dataset = new HashSet<>(); dataset.add(8); dataset.add(3); dataset.add(7); try (FileWriter fw = new FileWriter("\\Users\\Test.txt", true); // true -> append BufferedWriter bw = new BufferedWriter(f

symfony2自定义输入名称(symfony2 custom input name)

解决方案: 清空“UserType :: getName()”返回的值将删除参数的前缀。 因此“ company_mybundle_user [lastName] ”成为lastName 之前: // src/Company/MyBundle/Form/UserType.php // ... public function getName() { return 'company_mybundle_user'; } 后: // src/Company/MyBundle/Form/User

如何从unsigned char转换为long(How do I convert from unsigned char to long)

fromDecToBinary函数中有几个错误: 将'/0'替换为'/0' '\0' 。 在数组中存储'0' + tmpSubjectStatus % 2 。 为strtol调用添加适当的错误处理。 将返回类型更改为long 。 You have several errors in the fromDecToBinary function: Replace the '/0' with '\0'. Store '0' + tmpSubjectStatus % 2 in the array. Add

OnMapLoaded永远不会在Android上调用(OnMapLoaded is never call on Android)

从文档 : 如果由于连接问题导致地图永远不会加载,或者由于用户经常与地图交互而不断更改地图并且永远不会完成加载,则不会触发此事件。 因此,请检查连接并确保地图处于空闲状态。 From the documentation: This event will not fire if the map never loads due to connectivity issues, or if the map is continuously changing and never completes load

使HyperlinkListener与JeditorPane NullPointerException一起使用(Making HyperlinkListener Work with JeditorPane NullPointerException)

我找到了答案,我忘了把动作放在表格中。 sb.append("<form>"); 应该 sb.append("<form action=\"#\">");` I found the answer, i forgot to put action in the form. sb.append("<form>"); should be sb.append("<form action=\"#\">");`

错误:(23,26)不允许使用字符串类型(在'src'处,值为'pen')。(Error:(23, 26) String types not allowed (at 'src' with value 'pen').?)

错误消息清楚地表明您的错误。 您必须设置一个imageView的可绘制引用。 但是你设置了一个字符串: android:src="pen" 如果您有一个可绘制的(图像)命名笔,请将该行更改为: android:src="@drawable/pen" The error message says your error clearly. You have to set a drawable reference to an imageView. But you set a string: andr

数据结构按值对元素进行排序(Data Structure to sort elements by values)

我认为没有一个简单的数据结构。 收集频率数据时,频率会发生变化。 在收集所有字符串频率之后应该进行哪种排序。 我能想到的最简单的方法是: // psuedo-code final Map<String, Integer> stringFreq = ....; // it doesn't matter what kind of impl you use // collect the String vs frequency in stringFreq Map<String, Integer> r

Scala:如果在非平凡的超类中尚未指定的情况下,仅生成了案例类的hashCode()和equals()吗?(Scala: Is hashCode() & equals() for case classes only generated if not already specified in a non-trivial superclass?)

这是记录在案的行为。 Scala规范的第5.3.2节 (强调我的): 每个case类都隐式覆盖类scala.AnyRef的一些方法定义, 除非在case类本身中已经给出了相同方法的定义,或者在不同于AnyRef的case类的某个基类中给出了相同方法的具体定义 。 尤其是: 方法等于:(任意)布尔值是结构相等,其中两个实例相等,如果它们都属于有问题的案例类并且它们具有相等(相对于等于)构造函数参数(仅限于类的元素,即第一个参数)部分)。 方法hashCode:Int计算哈希码。 如果数据结构成员的

相关文章

更多

最新问答

更多
  • 图像TapGestureRecognizer未触发(Image TapGestureRecognizer not firing)
  • 从数组中选择项目(Selecting items from an array)
  • PhpStorm:简单的PHP表单不发布(PhpStorm: Simple PHP form not posting)
  • 如果语句只有Javascript中的数字(If statement with only a number in Javascript)
  • 截图Android中的黑色(Screenshot Black in Android)
  • 默认值如何在数据库中内部工作?(How does default value internally work in Database?)
  • 左连接不加入单个记录(Left Join Not Joining with a Single Record)
  • 在#sign drupal之后获取url参数(get url parameter after # sign drupal)
  • Crontab CD到目录(Crontab CD to Directory)
  • #inf c ++ visual studio(#inf c++ visual studio)
  • 使用Python将指数修改的高斯曲线拟合到数据(Fitting an exponential modified gaussian curve to data with Python)
  • Javascript - 具有音高和持续时间控制的文本到语音(Javascript - text to speech with pitch and duration control)
  • 群组和用户有多少通过?(Groups and Users has many oder has many through?)
  • 如何在简单的二叉树中选择节点所在的哪一侧?(How to pick which side a node is on in a simple binary tree?)
  • 在ImageView上添加TextView(Android)(Add TextView over ImageView (Android))
  • 使用工厂方法创建泛型(Using Factory Method to Create Generics)
  • cordova 4.1.2中的平台特定代码(platform specific code in cordova 4.1.2)
  • 使用php格式化日期[复制](Format date using php [duplicate])
  • 在Python中解析年,月,日,小时,分钟,秒(Parsing year, month, day, hour, minute, second in Python)
  • 用jquery替换图像和类(Replacing image and class with jquery)
  • 导入的module.submodule命名空间干扰彼此(imported module.submodule namespaces interfering with eachother)
  • 播放框架:提交按钮似乎不起作用(Play framework: Submit button doesn't seem to work)
  • 段落包括通过过渡带来的div(Paragraph covers div brought through transition)
  • 使用processing.Manager时对象是否重复?(Object duplicated when using processing.Manager?)
  • lxde意外退出(lxde quits unexpectedly)
  • 真正的Maven依赖是什么?(What really are Maven dependencies?)
  • 如何在我的代码中修复getJSON方法错误?(how to fix getJSON method error in my code?)
  • Google Analytics状态:已安装跟踪 - 但无法正常运行(Google Analytics Status: Tracking Installed - but isnt working)
  • 在模型文件中的非对象上调用成员函数num_rows()(Call to a member function num_rows() on a non-object in model file)
  • 有关UNIX中fork()函数的问题(Questions about the fork() function in UNIX)