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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:52:00+00:00 2026-05-24T00:52:00+00:00

I am having trouble with the user interface for an Activity I wrote. Basically

  • 0

I am having trouble with the user interface for an Activity I wrote. Basically it is a text view with a ToggleButton at the bottom of the screen, the TextView text is updated every X seconds while the button is toggled on. I am getting a NullPointerException in my onCreate, I think the UI resources are null? I have never coded a UI for Android so I am very confused but I think I have most of it correct.

Exception:

W/dalvikvm(  486): threadid=1: thread exiting with uncaught exception (group=0x400207e8)
E/AndroidRuntime(  486): FATAL EXCEPTION: main
E/AndroidRuntime(  486): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.miccbull.locator.app/com.miccbull.locator.app.LocatorActivity}: java.lang.NullPointerException
E/AndroidRuntime(  486):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  486):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  486):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(  486):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(  486):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  486):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  486):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  486):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  486):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  486):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  486):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  486):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  486): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  486):    at com.miccbull.locator.app.LocatorActivity.onCreate(LocatorActivity.java:53)
E/AndroidRuntime(  486):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  486):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  486):    ... 11 more

Here is my Activity’s onCreate method:

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


    locations = new LinkedList<String>();

    //---ToggleButton---
    textView = (TextView) findViewById(R.id.textView1);

    textView.setText("");

    //---ToggleButton---
    toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
    toggleButton.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) {
           if (((ToggleButton)v).isChecked())
                LocateOn();
           else
               LocateOff();
        }
    });

    setContentView(R.layout.main);
}

Here is my main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:weightSum="1"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ScrollView android:layout_width="fill_parent"
        android:id="@+id/widget54"
        android:layout_height="376dp">
        <TextView android:layout_width="fill_parent"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="TextView"
            android:id="@+id/textView1"
            android:layout_height="match_parent"></TextView>
    </ScrollView>


<!-- Linear view instead of scroll view. -->

    <LinearLayout android:layout_width="match_parent"
        android:id="@+id/linearLayout1"
        android:orientation="vertical"
        android:layout_height="378dp">
        <TextView android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="TextView"
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></TextView>
    </LinearLayout> 

    <ToggleButton android:text="ToggleButton"
        android:layout_width="fill_parent"
        android:id="@+id/toggleButton1"
        android:layout_height="wrap_content"></ToggleButton>

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout2"
        android:orientation="vertical">
    </LinearLayout> 

</LinearLayout>
  • 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-05-24T00:52:00+00:00Added an answer on May 24, 2026 at 12:52 am

    You need to call setContentView(R.layout.main); before you try to access any of the elements in the layout XML by the findViewById() method.

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

Sidebar

Related Questions

I am having some trouble invalidating user passwords every 60 days on my postgres
I am having trouble dealing with user registration in ASP.NET MVC3 Model Binding. Basically,
I'm having trouble granting privileges to another user in PostgreSQL 8.3. While the GRANT
I'm having trouble keeping my app responsive to user actions. Therefore, I'd like to
I'm having some trouble importing and accessing a private key with the ASPNET user.
im having trouble setting the Etag on a user's browser reliably. When a user
Having trouble with AR 2.3.5, e.g.: users = User.all( :select => u.id, c.user_id, :from
But I'm having trouble with a new user registration form. Can someone explain this
A poorly-written back-end system we interface with is having trouble with handling the load
I am having trouble with a function that checks if a set of user

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.