找不到ID为0x7f05003c的视图

时间:2014-04-23 10:21:25

标签: android eclipse fragment containers

我已经从几个网站搜索过答案,并且发现这些帮助很少。此外,我似乎在我的应用程序中使用片段的成功很少,但我知道无法让Eclipse ADT无法创建它们。在这种情况下,我得到了这里指定的错误:

    04-23 05:02:38.137: D/dalvikvm(370): GC_CONCURRENT freed 158K, 5% free 6519K/6791K, paused 4ms+3ms
04-23 05:02:38.157: E/FragmentManager(370): No view found for id 0x7f05003c (dls.strickwhitdevelopment.milledgevilletourist:id/container) for fragment PlaceholderFragment{406877b8 #0 id=0x7f05003c}
04-23 05:02:38.157: E/FragmentManager(370): Activity state:
04-23 05:02:38.167: D/FragmentManager(370):   Local FragmentActivity 4067deb8 State:
04-23 05:02:38.167: D/FragmentManager(370):     mCreated=truemResumed=false mStopped=false mReallyStopped=false
04-23 05:02:38.167: D/FragmentManager(370):     mLoadersStarted=false
04-23 05:02:38.177: D/FragmentManager(370):   Active Fragments in 4067ef78:
04-23 05:02:38.177: D/FragmentManager(370):     #0: PlaceholderFragment{406877b8 #0 id=0x7f05003c}
04-23 05:02:38.177: D/FragmentManager(370):       mFragmentId=#7f05003c mContainerId=#7f05003c mTag=null
04-23 05:02:38.188: D/FragmentManager(370):       mState=0 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
04-23 05:02:38.188: D/FragmentManager(370):       mAdded=true mRemoving=false mResumed=false mFromLayout=false mInLayout=false
04-23 05:02:38.188: D/FragmentManager(370):       mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
04-23 05:02:38.188: D/FragmentManager(370):       mRetainInstance=false mRetaining=false mUserVisibleHint=true
04-23 05:02:38.197: D/FragmentManager(370):       mFragmentManager=FragmentManager{4067ef78 in MainActivity{4067deb8}}
04-23 05:02:38.197: D/FragmentManager(370):       mActivity=dls.strickwhitdevelopment.milledgevilletourist.MainActivity@4067deb8
04-23 05:02:38.197: D/FragmentManager(370):   Added Fragments:
04-23 05:02:38.207: D/FragmentManager(370):     #0: PlaceholderFragment{406877b8 #0 id=0x7f05003c}
04-23 05:02:38.207: D/FragmentManager(370):   FragmentManager misc state:
04-23 05:02:38.207: D/FragmentManager(370):     mActivity=dls.strickwhitdevelopment.milledgevilletourist.MainActivity@4067deb8
04-23 05:02:38.207: D/FragmentManager(370):     mContainer=android.support.v4.app.FragmentActivity$2@4067f880
04-23 05:02:38.217: D/FragmentManager(370):     mCurState=2 mStateSaved=false mDestroyed=false
04-23 05:02:38.217: D/FragmentManager(370):   View Hierarchy:
04-23 05:02:38.217: D/FragmentManager(370):     com.android.internal.policy.impl.PhoneWindow$DecorView{40684718 V.E..... ... 0,0-0,0}
04-23 05:02:38.227: D/FragmentManager(370):       android.widget.LinearLayout{406853c8 V.E..... ... 0,0-0,0}
04-23 05:02:38.227: D/FragmentManager(370):         android.view.ViewStub{40687500 G.E..... ... 0,0-0,0 #1020290}
04-23 05:02:38.227: D/FragmentManager(370):         android.widget.FrameLayout{406879d0 V.E..... ... 0,0-0,0}
04-23 05:02:38.237: D/FragmentManager(370):           android.support.v7.internal.widget.NativeActionModeAwareLayout{40688758 V.E..... ... 0,0-0,0 #7f05001a app:id/action_bar_root}
04-23 05:02:38.237: D/FragmentManager(370):             android.support.v7.internal.widget.ActionBarContainer{406892d0 V.ED.... ... 0,0-0,0 #7f05001b app:id/action_bar_container}
04-23 05:02:38.237: D/FragmentManager(370):               android.support.v7.internal.widget.ActionBarView{4068bfc0 V.E..... ... 0,0-0,0 #7f05001c app:id/action_bar}
04-23 05:02:38.247: D/FragmentManager(370):                 android.widget.LinearLayout{4069d7f0 G.....C. ... 0,0-0,0}
04-23 05:02:38.247: D/FragmentManager(370):                   android.widget.ImageView{4069e468 G.ED.... ... 0,0-0,0 #7f050021 app:id/up}
04-23 05:02:38.257: D/FragmentManager(370):                   android.widget.LinearLayout{4069e758 V.E..... ... 0,0-0,0}
04-23 05:02:38.257: D/FragmentManager(370):                     android.widget.TextView{4069ed18 V.ED.... ... 0,0-0,0 #7f050022 app:id/action_bar_title}
04-23 05:02:38.257: D/FragmentManager(370):                     android.widget.TextView{4069fad8 G.ED.... ... 0,0-0,0 #7f050023 app:id/action_bar_subtitle}
04-23 05:02:38.267: D/FragmentManager(370):                 android.support.v7.internal.widget.ActionBarView$HomeView{40697b60 VFE...C. ... 0,0-0,0}
04-23 05:02:38.267: D/FragmentManager(370):                   android.widget.ImageView{4069b228 G.ED.... ... 0,0-0,0 #7f050021 app:id/up}
04-23 05:02:38.267: D/FragmentManager(370):                   android.widget.ImageView{4069bc98 V.ED.... ... 0,0-0,0 #7f050014 app:id/home}
04-23 05:02:38.278: D/FragmentManager(370):               android.support.v7.internal.widget.ActionBarContextView{406a11e0 G.E..... ... 0,0-0,0 #7f05001d app:id/action_context_bar}
04-23 05:02:38.278: D/FragmentManager(370):             android.widget.FrameLayout{406a2df0 V.E..... ... 0,0-0,0 #1020002 android:id/content}
04-23 05:02:38.278: D/FragmentManager(370):               android.widget.RelativeLayout{406a5298 V.E..... ... 0,0-0,0}
04-23 05:02:38.287: D/FragmentManager(370):                 android.widget.TextView{406a57b0 V.ED.... ... 0,0-0,0 #7f0500c4 app:id/welcome1}
04-23 05:02:38.287: D/FragmentManager(370):                 android.widget.TextView{4062f730 V.ED.... ... 0,0-0,0 #7f0500c5 app:id/welcome2}
04-23 05:02:38.287: D/FragmentManager(370):                 android.widget.TextView{4063e618 V.ED.... ... 0,0-0,0 #7f0500c6 app:id/welcome3}
04-23 05:02:38.297: D/FragmentManager(370):                 android.widget.Button{4062c878 VFED..C. ... 0,0-0,0 #7f0500c7 app:id/ENTER}
04-23 05:02:38.297: D/FragmentManager(370):             android.support.v7.internal.widget.ActionBarContainer{406a31b8 G.ED.... ... 0,0-0,0 #7f05001e app:id/split_action_bar}
04-23 05:02:38.297: D/AndroidRuntime(370): Shutting down VM
04-23 05:02:38.297: W/dalvikvm(370): threadid=1: thread exiting with uncaught exception (group=0x40014760)
04-23 05:02:38.317: E/AndroidRuntime(370): FATAL EXCEPTION: main
04-23 05:02:38.317: E/AndroidRuntime(370): java.lang.RuntimeException: Unable to start activity ComponentInfo{dls.strickwhitdevelopment.milledgevilletourist/dls.strickwhitdevelopment.milledgevilletourist.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f05003c (dls.strickwhitdevelopment.milledgevilletourist:id/container) for fragment PlaceholderFragment{406877b8 #0 id=0x7f05003c}
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.ActivityThread.access$1500(ActivityThread.java:123)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.os.Looper.loop(Looper.java:126)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.ActivityThread.main(ActivityThread.java:3997)
04-23 05:02:38.317: E/AndroidRuntime(370):  at java.lang.reflect.Method.invokeNative(Native Method)
04-23 05:02:38.317: E/AndroidRuntime(370):  at java.lang.reflect.Method.invoke(Method.java:491)
04-23 05:02:38.317: E/AndroidRuntime(370):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-23 05:02:38.317: E/AndroidRuntime(370):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-23 05:02:38.317: E/AndroidRuntime(370):  at dalvik.system.NativeStart.main(Native Method)
04-23 05:02:38.317: E/AndroidRuntime(370): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f05003c (dls.strickwhitdevelopment.milledgevilletourist:id/container) for fragment PlaceholderFragment{406877b8 #0 id=0x7f05003c}
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:930)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1132)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.Activity.performStart(Activity.java:4320)
04-23 05:02:38.317: E/AndroidRuntime(370):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1709)
04-23 05:02:38.317: E/AndroidRuntime(370):  ... 11 more
04-23 05:02:45.668: I/Process(370): Sending signal. PID: 370 SIG: 9

这发生在虚拟设备的每个Android版本上。

这是我的activity_main:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dls.strickwhitdevelopment.milledgevilletourist.MainActivity"
tools:ignore="MergeRootFrame" />

这是我的fragment_main:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="dls.strickwhitdevelopment.milledgevilletourist.Main_Activity$PlaceholderFragment" >

    <TextView
        android:id="@+id/welcome1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/welcome1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/welcome2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/welcome1"
        android:layout_marginTop="7dp"
        android:layout_centerHorizontal="true"
        android:text="@string/welcome2"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/welcome3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/welcome2"
        android:layout_marginTop="7dp"
        android:layout_centerHorizontal="true"
        android:text="@string/welcome3"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/ENTER"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/welcome3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="25dp"
        android:text="@string/enter" />

</RelativeLayout>

这是我的MainActivity.java:

    package dls.strickwhitdevelopment.milledgevilletourist;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class MainActivity extends ActionBarActivity {

    private Button ENTER;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);

        ENTER = (Button) findViewById(R.id.ENTER);
        ENTER.setOnClickListener(new View.OnClickListener() {

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

                Intent myIntent = new Intent(currentView.getContext(), Service_Selection.class);
                startActivityForResult(myIntent, 0);

            }
        });
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main,
                    container, false);
            return rootView;
        }
    }

}

Lint显示没有错误,但这是在安装后直接发生并尝试打开应用程序。任何帮助将不胜感激。我使用的是Android开发人员工具

Build:v22.6.2-1085508

1 个答案:

答案 0 :(得分:1)

从MainActivity OnCreate中你应该执行

setContentView(R.layout.activity_main)

由于您在mainActivity中使用R.layout.fragment_main,因此片段管理器无法找到R.id.Container

的视图