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 7889161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:01:30+00:00 2026-06-03T06:01:30+00:00

I am new to Andriod and having difficult time adding controls (Views) on top

  • 0

I am new to Andriod and having difficult time adding controls (Views) on top of my GLSurfaceView.I want this to be added on a corner. (say bottom-right)
Initially I wanted to add Joystick like widget,but at first I wanted to add “Left”,”Right”,”Top”,”Down” buttons.
I created a layout XML file as below :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <View
        android:id="@+id/viewControls"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relativeLayout1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="140dp" >
    </RelativeLayout>

    <Button
        android:id="@+id/buttonR"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/relativeLayout1"
        android:text="R" />

    <Button
        android:id="@+id/buttonL"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="L" />

</RelativeLayout>

And in my Activity ,I tried as follows:

public class MyOpenGL2Activity extends Activity {

    private GLSurfaceView mGLview;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        mGLview=new MyOpenGL2SurfaceView(this);

        FrameLayout flayout=new FrameLayout(this);     
        flayout.addView(mGLview);

        View controller=findViewById(R.id.viewControls);

        flayout.addView(controller);       


        setContentView(flayout);
}
...

But the application crashes saying

05-05 14:40:08.015: W/dalvikvm(2258): threadid=1: thread exiting with
uncaught exception (group=0x40a841f8) 05-05 14:40:08.023:
E/AndroidRuntime(2258): FATAL EXCEPTION: main 05-05 14:40:08.023:
E/AndroidRuntime(2258): java.lang.RuntimeException: Unable to start
activity ComponentInfo{ausoft.opengl/ausoft.opengl.MyOpenGL2Activity}:
java.lang.NullPointerException 05-05 14:40:08.023:
E/AndroidRuntime(2258): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
05-05 14:40:08.023: E/AndroidRuntime(2258): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-05 14:40:08.023: E/AndroidRuntime(2258): at
android.app.ActivityThread.access$600(ActivityThread.java:122) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-05 14:40:08.023: E/AndroidRuntime(2258): at
android.os.Handler.dispatchMessage(Handler.java:99) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
android.os.Looper.loop(Looper.java:137) 05-05 14:40:08.023:
E/AndroidRuntime(2258): at
android.app.ActivityThread.main(ActivityThread.java:4340) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
java.lang.reflect.Method.invokeNative(Native Method) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
java.lang.reflect.Method.invoke(Method.java:511) 05-05 14:40:08.023:
E/AndroidRuntime(2258): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-05 14:40:08.023: E/AndroidRuntime(2258): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
dalvik.system.NativeStart.main(Native Method) 05-05 14:40:08.023:
E/AndroidRuntime(2258): Caused by: java.lang.NullPointerException
05-05 14:40:08.023: E/AndroidRuntime(2258): at
android.view.ViewGroup.addView(ViewGroup.java:3165) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
android.view.ViewGroup.addView(ViewGroup.java:3152) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
ausoft.opengl.MyOpenGL2Activity.onCreate(MyOpenGL2Activity.java:35)
05-05 14:40:08.023: E/AndroidRuntime(2258): at
android.app.Activity.performCreate(Activity.java:4465) 05-05
14:40:08.023: E/AndroidRuntime(2258): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-05 14:40:08.023: E/AndroidRuntime(2258): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
05-05 14:40:08.023: E/AndroidRuntime(2258): … 11 more

Any tips?

  • 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-03T06:01:31+00:00Added an answer on June 3, 2026 at 6:01 am

    You are trying to findViewById(R.id.viewControls); but you have not called setContentView() before… Where is the view viewControls ?


    If you want, you can create the view like this

    View controller = new View(this.getApplicationContext());
    

    or whatever…

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

Sidebar

Related Questions

For Andriod I have this code: public Tank(int color) { bounds = new RectF();
Hi I am new into android development and I am having trouble into this
this is a real basic question, but I am having a frustrating time learning
So I'm having a problem making a new socket. I had this program that
Hi I am new to android and I am having an issue I have
I am new to Android i need to implement buttons having the size of
I am new to Android. I like having the free range of drawing objects
I'm new to Android, and Java altogether for that matter and I'm having a
I'm relatively new to Android programming, and am having a problem with inflation. I'm
im new with andriod and err, im not sure if its really a need

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.