Android Studio can't change Activity.


  • QA Engineer

    When establishing a new module for the project, BlankActivity is selected, a module is being created with such files in the res/layout folder: activity_main.xml content_main.xml As I understood, activity_main.xml is include where it connects. content_main.xml and the data are read from it. Problem: If you create your layout, in MainActivity.java, change setContentView(R.layout.activity_main);

      setContentView(R.layout.mylayout);
    

    the programme is departing (Programme stops)

    E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{...}: java.lang.NullPointerException
    

    How do you fix this mistake? Yeah, I can in activity...mainly in the inclused content-mainly write my layout, but how do I put it on the code?



  • You've got an unknown variable trying to initiate an element of the old marking, something's not new.

    Decision:

    Remove the entire code. onCreate() Except

    super.onCreate(savedInstanceState)
    setContentView(R.layout.mylayout)
    

    And all the other methods will activate. It's gonna work.

    After that, take the books/losses on the Android and read until you realize what you've done for a mistake. and how to live




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2