Why Caused by: java.lang.IllegalStateException: surface_view must not be null? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?getActivity() returns null in Fragment functionWhy fragments, and when to use fragments instead of activities?Android. Fragment getActivity() sometimes returns nullDuplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragmentError when starting a new activity Androidjava.lang.IllegalStateException: Fragment not attached to ActivityKotlin and new ActivityTestRule : The @Rule must be publicjava.lang.IllegalStateException: TextView must not be null (Android/Kotlin)override onCreateAnimation FATAL EXCEPTION to java.lang.IllegalStateException : must not be nullCause: buildOutput.apkData must not be null

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

How to deal with a team lead who never gives me credit?

How can I make names more distinctive without making them longer?

What causes the vertical darker bands in my photo?

What is the musical term for a note that continously plays through a melody?

Gastric acid as a weapon

Single word antonym of "flightless"

Is there a "higher Segal conjecture"?

What is this single-engine low-wing propeller plane?

Should gear shift center itself while in neutral?

If 'B is more likely given A', then 'A is more likely given B'

What is the longest distance a 13th-level monk can jump while attacking on the same turn?

Why are there no cargo aircraft with "flying wing" design?

Do I really need recursive chmod to restrict access to a folder?

How to motivate offshore teams and trust them to deliver?

How do I stop a creek from eroding my steep embankment?

Models of set theory where not every set can be linearly ordered

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

Why is "Consequences inflicted." not a sentence?

How does cp -a work

How do I mention the quality of my school without bragging

Using et al. for a last / senior author rather than for a first author

How to bypass password on Windows XP account?

Stars Make Stars



Why Caused by: java.lang.IllegalStateException: surface_view must not be null?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?getActivity() returns null in Fragment functionWhy fragments, and when to use fragments instead of activities?Android. Fragment getActivity() sometimes returns nullDuplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragmentError when starting a new activity Androidjava.lang.IllegalStateException: Fragment not attached to ActivityKotlin and new ActivityTestRule : The @Rule must be publicjava.lang.IllegalStateException: TextView must not be null (Android/Kotlin)override onCreateAnimation FATAL EXCEPTION to java.lang.IllegalStateException : must not be nullCause: buildOutput.apkData must not be null



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying out this qeReader lib in my app. I have an activity, where I embedd a SurfaceFragment. Here the fragment_surface layout:



<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<SurfaceView
android:id="@+id/surface_view"
android:layout_width="300dp"
android:layout_height="300dp"/>
</LinearLayout>


and my SurfaceFragment :



 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? 
return inflater.inflate(R.layout.fragment_surface, container, false)



and in my activity I call:



val fragmentManager = this.supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.framelayout_qr, SurfaceFragment())
fragmentTransaction.commit()


and in my activities layout:



<FrameLayout
android:id="@+id/framelayout_qr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>


Later on I have to access from my activity the surface_view, but this crashes:




Caused by: java.lang.IllegalStateException: surface_view must not be
null




Q1: All my R are marked red and labeled as Unresolved reference: R , although they are imported in the code. But I can run the app, until crash. Why is it marked red, but obviously imported?



Q2: I've read that I do not need those findViewById() things in Kotlin anymore? Why is surface_view null from the activity, although it is replaced in the FragmentTransaction?










share|improve this question




























    0















    I am trying out this qeReader lib in my app. I have an activity, where I embedd a SurfaceFragment. Here the fragment_surface layout:



    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SurfaceView
    android:id="@+id/surface_view"
    android:layout_width="300dp"
    android:layout_height="300dp"/>
    </LinearLayout>


    and my SurfaceFragment :



     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? 
    return inflater.inflate(R.layout.fragment_surface, container, false)



    and in my activity I call:



    val fragmentManager = this.supportFragmentManager
    val fragmentTransaction = fragmentManager.beginTransaction()
    fragmentTransaction.replace(R.id.framelayout_qr, SurfaceFragment())
    fragmentTransaction.commit()


    and in my activities layout:



    <FrameLayout
    android:id="@+id/framelayout_qr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    />


    Later on I have to access from my activity the surface_view, but this crashes:




    Caused by: java.lang.IllegalStateException: surface_view must not be
    null




    Q1: All my R are marked red and labeled as Unresolved reference: R , although they are imported in the code. But I can run the app, until crash. Why is it marked red, but obviously imported?



    Q2: I've read that I do not need those findViewById() things in Kotlin anymore? Why is surface_view null from the activity, although it is replaced in the FragmentTransaction?










    share|improve this question
























      0












      0








      0








      I am trying out this qeReader lib in my app. I have an activity, where I embedd a SurfaceFragment. Here the fragment_surface layout:



      <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <SurfaceView
      android:id="@+id/surface_view"
      android:layout_width="300dp"
      android:layout_height="300dp"/>
      </LinearLayout>


      and my SurfaceFragment :



       override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? 
      return inflater.inflate(R.layout.fragment_surface, container, false)



      and in my activity I call:



      val fragmentManager = this.supportFragmentManager
      val fragmentTransaction = fragmentManager.beginTransaction()
      fragmentTransaction.replace(R.id.framelayout_qr, SurfaceFragment())
      fragmentTransaction.commit()


      and in my activities layout:



      <FrameLayout
      android:id="@+id/framelayout_qr"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintBottom_toBottomOf="parent"
      />


      Later on I have to access from my activity the surface_view, but this crashes:




      Caused by: java.lang.IllegalStateException: surface_view must not be
      null




      Q1: All my R are marked red and labeled as Unresolved reference: R , although they are imported in the code. But I can run the app, until crash. Why is it marked red, but obviously imported?



      Q2: I've read that I do not need those findViewById() things in Kotlin anymore? Why is surface_view null from the activity, although it is replaced in the FragmentTransaction?










      share|improve this question














      I am trying out this qeReader lib in my app. I have an activity, where I embedd a SurfaceFragment. Here the fragment_surface layout:



      <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <SurfaceView
      android:id="@+id/surface_view"
      android:layout_width="300dp"
      android:layout_height="300dp"/>
      </LinearLayout>


      and my SurfaceFragment :



       override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? 
      return inflater.inflate(R.layout.fragment_surface, container, false)



      and in my activity I call:



      val fragmentManager = this.supportFragmentManager
      val fragmentTransaction = fragmentManager.beginTransaction()
      fragmentTransaction.replace(R.id.framelayout_qr, SurfaceFragment())
      fragmentTransaction.commit()


      and in my activities layout:



      <FrameLayout
      android:id="@+id/framelayout_qr"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintBottom_toBottomOf="parent"
      />


      Later on I have to access from my activity the surface_view, but this crashes:




      Caused by: java.lang.IllegalStateException: surface_view must not be
      null




      Q1: All my R are marked red and labeled as Unresolved reference: R , although they are imported in the code. But I can run the app, until crash. Why is it marked red, but obviously imported?



      Q2: I've read that I do not need those findViewById() things in Kotlin anymore? Why is surface_view null from the activity, although it is replaced in the FragmentTransaction?







      android-fragments android-activity kotlin






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 16:17









      NoamEpsteinNoamEpstein

      526




      526






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Q1: R is a reference to the set of resources that are generated when you "build" the app. The first time it won't exist, then subsequent times it will exist. This gets reset every time you "clean" the app. Pressing "rebuild" will run a clean first, then a build. Although this is the way the Android resource system is designed, the Android Studio inspection isn't smart enough to know this the first time round, so it mistakenly thinks you'll get a compile time error. If this persists, try invaliding caches in Android Studio, doing a gradle sync, then rebuilding the project.



          Q2: The Kotlin Android Extensions plugin is a feature that came out in the last couple of years that avoids having to using findViewById(...) to access views and widgets. You can only access views and widgets that are declared in an xml file from the Kotlin file which you use setContentView(layout_xml_file) in.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067064%2fwhy-caused-by-java-lang-illegalstateexception-surface-view-must-not-be-null%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Q1: R is a reference to the set of resources that are generated when you "build" the app. The first time it won't exist, then subsequent times it will exist. This gets reset every time you "clean" the app. Pressing "rebuild" will run a clean first, then a build. Although this is the way the Android resource system is designed, the Android Studio inspection isn't smart enough to know this the first time round, so it mistakenly thinks you'll get a compile time error. If this persists, try invaliding caches in Android Studio, doing a gradle sync, then rebuilding the project.



            Q2: The Kotlin Android Extensions plugin is a feature that came out in the last couple of years that avoids having to using findViewById(...) to access views and widgets. You can only access views and widgets that are declared in an xml file from the Kotlin file which you use setContentView(layout_xml_file) in.






            share|improve this answer



























              1














              Q1: R is a reference to the set of resources that are generated when you "build" the app. The first time it won't exist, then subsequent times it will exist. This gets reset every time you "clean" the app. Pressing "rebuild" will run a clean first, then a build. Although this is the way the Android resource system is designed, the Android Studio inspection isn't smart enough to know this the first time round, so it mistakenly thinks you'll get a compile time error. If this persists, try invaliding caches in Android Studio, doing a gradle sync, then rebuilding the project.



              Q2: The Kotlin Android Extensions plugin is a feature that came out in the last couple of years that avoids having to using findViewById(...) to access views and widgets. You can only access views and widgets that are declared in an xml file from the Kotlin file which you use setContentView(layout_xml_file) in.






              share|improve this answer

























                1












                1








                1







                Q1: R is a reference to the set of resources that are generated when you "build" the app. The first time it won't exist, then subsequent times it will exist. This gets reset every time you "clean" the app. Pressing "rebuild" will run a clean first, then a build. Although this is the way the Android resource system is designed, the Android Studio inspection isn't smart enough to know this the first time round, so it mistakenly thinks you'll get a compile time error. If this persists, try invaliding caches in Android Studio, doing a gradle sync, then rebuilding the project.



                Q2: The Kotlin Android Extensions plugin is a feature that came out in the last couple of years that avoids having to using findViewById(...) to access views and widgets. You can only access views and widgets that are declared in an xml file from the Kotlin file which you use setContentView(layout_xml_file) in.






                share|improve this answer













                Q1: R is a reference to the set of resources that are generated when you "build" the app. The first time it won't exist, then subsequent times it will exist. This gets reset every time you "clean" the app. Pressing "rebuild" will run a clean first, then a build. Although this is the way the Android resource system is designed, the Android Studio inspection isn't smart enough to know this the first time round, so it mistakenly thinks you'll get a compile time error. If this persists, try invaliding caches in Android Studio, doing a gradle sync, then rebuilding the project.



                Q2: The Kotlin Android Extensions plugin is a feature that came out in the last couple of years that avoids having to using findViewById(...) to access views and widgets. You can only access views and widgets that are declared in an xml file from the Kotlin file which you use setContentView(layout_xml_file) in.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 16:39









                Can_of_aweCan_of_awe

                155110




                155110





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067064%2fwhy-caused-by-java-lang-illegalstateexception-surface-view-must-not-be-null%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко