# App stürzt ab.



## Lucaaa (12. Sep 2018)

Ich möchte ein Fragment in meiner Activity anzeigen.
Doch beim öffnen der App stürzt diese ab.


```
package com.ludevstudio.passwordmanager;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.FragmentManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;

public class MainActivity extends FragmentActivity{

    public IntroStep1IntroductionFragment step1;
    public IntroStep2PasswordIntroductionFragment step2;

    public android.app.FragmentManager fragmentManager;
    public FragmentTransaction fragmentTransaction;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


            initIntroPages();

           }

        // init the Fragments for the Intro Page
    private void initIntroPages() {
        step1 = (IntroStep1IntroductionFragment) Fragment.instantiate(this, IntroStep1IntroductionFragment.class.getName(), null);
        step2 = (IntroStep2PasswordIntroductionFragment) Fragment.instantiate(this, IntroStep2PasswordIntroductionFragment.class.getName(), null);
        initFragmentManagement();
    }

    private void  initFragmentManagement() {
        fragmentManager = getFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();

        fragmentTransaction.add(R.id.intro_container, step1);
        fragmentTransaction.commit();
    }

}
```

Das Fragment:

```
package com.ludevstudio.passwordmanager;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class IntroStep1IntroductionFragment extends Fragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        // load the layout file
        View view = inflater.inflate(R.layout.intro_step1_introduction, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }
}
```

MainActivity layout file

```
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout android:layout_width="match_parent"
    android:id="@+id/intro_container"
      android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">


</RelativeLayout>
```

Logcat:

```
09-12 20:09:08.199 5688-5696/? E/zygote: Failed sending reply to debugger: Broken pipe
09-12 20:09:08.724 5688-5688/? E/FragmentManager: No view found for id 0x7f09001b (passwordmanager.ludevstudio.com.passwordmanager:layout/activity_main) for fragment IntroStep1IntroductionFragment{f6b431f #1 id=0x7f09001b}
09-12 20:09:08.725 5688-5688/? E/FragmentManager: Activity state:
09-12 20:09:08.726 5688-5688/? E/FragmentManager:   Local Activity 819366c State:
        mResumed=false mStopped=false mFinished=false
        mChangingConfigurations=false
09-12 20:09:08.727 5688-5688/? E/FragmentManager:     mCurrentConfig={1.0 310mcc260mnc [en_US] ldltr sw411dp w411dp h750dp 560dpi nrml long port finger qwerty/v/v -nav/h appBounds=Rect(0, 0 - 1440, 2712) s.6}
        mLoadersStarted=false
        Active Fragments in 4d94435:
          #0: ReportFragment{94860ca #0 android.arch.lifecycle.LifecycleDispatcher.report_fragment_tag}
09-12 20:09:08.733 5688-5688/? E/FragmentManager:         mFragmentId=#0 mContainerId=#0 mTag=android.arch.lifecycle.LifecycleDispatcher.report_fragment_tag
09-12 20:09:08.734 5688-5688/? E/FragmentManager:         mState=2 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
09-12 20:09:08.740 5688-5688/? E/FragmentManager:         mAdded=true mRemoving=false mFromLayout=false mInLayout=false
09-12 20:09:08.741 5688-5688/? E/FragmentManager:         mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
            mRetainInstance=false mRetaining=false mUserVisibleHint=true
            mFragmentManager=FragmentManager{4d94435 in HostCallbacks{78af23b}}
            mHost=android.app.Activity$HostCallbacks@78af23b
09-12 20:09:08.742 5688-5688/? E/FragmentManager:         Child FragmentManager{994d58 in ReportFragment{94860ca}}:
              FragmentManager misc state:
09-12 20:09:08.743 5688-5688/? E/FragmentManager:             mHost=android.app.Activity$HostCallbacks@78af23b
                mContainer=android.app.Fragment$1@e6eeb1
                mParent=ReportFragment{94860ca #0 android.arch.lifecycle.LifecycleDispatcher.report_fragment_tag}
09-12 20:09:08.744 5688-5688/? E/FragmentManager:             mCurState=2 mStateSaved=false mDestroyed=false
          #1: IntroStep1IntroductionFragment{f6b431f #1 id=0x7f09001b}
            mFragmentId=#7f09001b mContainerId=#7f09001b mTag=null
            mState=1 mIndex=1 mWho=android:fragment:1 mBackStackNesting=0
09-12 20:09:08.745 5688-5688/? E/FragmentManager:         mAdded=true mRemoving=false mFromLayout=false mInLayout=false
            mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
            mRetainInstance=false mRetaining=false mUserVisibleHint=true
            mFragmentManager=FragmentManager{4d94435 in HostCallbacks{78af23b}}
            mHost=android.app.Activity$HostCallbacks@78af23b
        Added Fragments:
          #0: ReportFragment{94860ca #0 android.arch.lifecycle.LifecycleDispatcher.report_fragment_tag}
          #1:
09-12 20:09:08.746 5688-5688/? E/FragmentManager: IntroStep1IntroductionFragment{f6b431f #1 id=0x7f09001b}
        FragmentManager misc state:
          mHost=android.app.Activity$HostCallbacks@78af23b
09-12 20:09:08.747 5688-5688/? E/FragmentManager:       mContainer=android.app.Activity$HostCallbacks@78af23b
          mCurState=2 mStateSaved=false mDestroyed=false
      Looper (main, tid 2) {cf3bf96}
        Message 0: { when=+9s797ms what=132 target=android.app.ActivityThread$H }
        (Total messages: 1, polling=false, quitting=false)
      Local FragmentActivity 819366c State:
        mCreated=falsemResumed=false mStopped=true mReallyStopped=true
      FragmentManager misc state:
        mHost=android.support.v4.app.FragmentActivity$HostCallbacks@c2c7717
        mContainer=android.support.v4.app.FragmentActivity$HostCallbacks@c2c7717
09-12 20:09:08.748 5688-5688/? E/FragmentManager:     mCurState=1 mStateSaved=false mStopped=false mDestroyed=false
09-12 20:09:08.750 5688-5688/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: passwordmanager.ludevstudio.com.passwordmanager, PID: 5688
    java.lang.RuntimeException: Unable to start activity ComponentInfo{passwordmanager.ludevstudio.com.passwordmanager/com.ludevstudio.passwordmanager.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f09001b (passwordmanager.ludevstudio.com.passwordmanager:layout/activity_main) for fragment IntroStep1IntroductionFragment{f6b431f #1 id=0x7f09001b}
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f09001b (passwordmanager.ludevstudio.com.passwordmanager:layout/activity_main) for fragment IntroStep1IntroductionFragment{f6b431f #1 id=0x7f09001b}
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
        at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2415)
        at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2194)
        at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2148)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2049)
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3044)
        at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2991)
        at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:178)
        at android.app.Activity.performCreateCommon(Activity.java:6969)
        at android.app.Activity.performCreate(Activity.java:6977)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
```


----------



## mihe7 (12. Sep 2018)

Evtl. hilft https://stackoverflow.com/questions/7508044/android-fragment-no-view-found-for-id/29908804#29908804


----------



## Lucaaa (13. Sep 2018)

Das Problem war, das ich kein Layout gesetzt habe. Die Klasse war von AndroidStudio eigentlich generiert worden, deshalb habe ich daran nicht gedacht...
`setContentView(R.layout.activity_main);`


----------

