Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8210287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:01:20+00:00 2026-06-07T10:01:20+00:00

here`s my problem: In my app, I use 2 layouts; one being for the

  • 0

here`s my problem:

In my app, I use 2 layouts; one being for the main menu and the other one is the actual in-game layout. When I start my game, I want the main-menu layout the be removed. I thought about doing so using

myView.setVisibility(View.GONE);

And then make the other layout using the same method.

The problem is that when I try to make the layout disappear, my app closes and the message box telling me so appears.

EDIT: The folowing code has changed

public class DemoReelActivity extends Activity implements OnClickListener{

private GLSurfaceView mGLView;
private View mainMenu;                          

Button newGame = null;

Button shoot = null;
SeekBar power = null;

TextView force = null;

byte forcePct = 0;

ball[] ballSet; 


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

mainMenu =  findViewById(R.layout.main_menu);                                                                                          setContentView(R.layout.main_menu);                      

    newGame = (Button) findViewById(R.id.button1);
    newGame.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    startGame();

}

public void startGame()
{
    //Remove the main_menu view
    mainMenu.setVisibility(View.GONE);
    mGLView.setVisibility(View.VISIBLE);

    // Create a GLSurfaceView instance and set it
    mGLView = new OpenGLES10SurfaceView(this);
    setContentView(mGLView);

    //Add the main.xml layout over the OpenGL one
    LayoutInflater inflater = getLayoutInflater();
    View tmpView;
    tmpView = inflater.inflate(R.layout.main, null);
    getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT));

    //Initialize all the buttons and stuff
    The code here is okay, I know it for sure.

    //Allocate enaugh memory for 16 balls(14 regular plus the black and white ball)
    ballSet = new ball[16];

    //Create all the balls needed to play
    for(byte i=0;i<16;i++)
    {
        new ball(i);
    }

}

}

This is the main_menu.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"  
    android:paddingLeft="100dp"
    android:paddingTop="80dp"
    android:orientation="vertical" >


    <Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="@string/newGame" android:layout_marginBottom="40dp" android:layout_marginLeft="10dp"/>



</LinearLayout>

And last but not least here is my LogCat:

    07-10 19:28:42.020: E/AndroidRuntime(350): Uncaught handler: thread main exiting due to uncaught exception
    07-10 19:28:42.032: E/AndroidRuntime(350): java.lang.NullPointerException
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.desgraff.demoreel.DemoReelActivity.startGame(DemoReelActivity.java:91)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.desgraff.demoreel.DemoReelActivity.onClick(DemoReelActivity.java:80)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.View.performClick(View.java:2364)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.View.onTouchEvent(View.java:4179)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.View.dispatchTouchEvent(View.java:3709)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.os.Handler.dispatchMessage(Handler.java:99)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.os.Looper.loop(Looper.java:123)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at android.app.ActivityThread.main(ActivityThread.java:4363)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at java.lang.reflect.Method.invokeNative(Native Method)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at java.lang.reflect.Method.invoke(Method.java:521)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    07-10 19:28:42.032: E/AndroidRuntime(350):  at dalvik.system.NativeStart.main(Native Method)

Sorry for the long post btw but I am new to android(and Java for that matter)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:01:21+00:00Added an answer on June 7, 2026 at 10:01 am

    I see it now. You need to give the root element in you XML an id and pass this id to findViewById(), you cannot load a layout by passing the whole XML file.

    First, add the id attribute to your LinearLayout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_menu"
        android:layout_width="fill_parent"
        ...
    

    Second, change these:

    private View mainMenu;
    ...
    mainMenu =  findViewById(R.layout.main_menu);
    

    like so:

    private LinearLayout mainMenu;
    ...
    mainMenu = (LinearLayout) findViewById(R.id.main_menu);
    

    Also, you are about to get a NullPointerException:

    mGLView.setVisibility(View.VISIBLE); // Remove me.
    
    // Create a GLSurfaceView instance and set it
    mGLView = new OpenGLES10SurfaceView(this);
    

    Since you are initializing mGLView after you try to make it (nothing) visible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one HTML file located in app/views/layouts/application.html.erb I use <%=yield=> to render the
here is the problem : there is classic asp app which is calling lame.exe
Here's my problem. I built a web app, and naturally kept the data in
Here is my problem. I am trying to store data from my web app
so here is the problem. I am currently creating an Android app that is
I've already integrated facebook login in my Android app but my problem is here:-
This sounds confusing but isn't. Here is the problem: application is hosted at www.site.com/app
I am facing a problem on developing my web app, here is the description:
I'm developing an app and have run into a problem with asynchronous calls... Here's
I'm making use of JqueryMobile for building my android app. The problem I'm facing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.