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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:35:27+00:00 2026-05-23T09:35:27+00:00

My Code: public class My_Application extends Activity { public ToggleButton privBtn = (ToggleButton) findViewById(R.id.privacyShow);

  • 0

My Code:

public class My_Application extends Activity {

public ToggleButton privBtn = (ToggleButton) findViewById(R.id.privacyShow);
public LinearLayout privLay = (LinearLayout) findViewById(R.id.privacyLayout);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    privBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if(privBtn.isChecked()) {
                privLay.setVisibility(LinearLayout.VISIBLE);
            }
            else {
                privLay.setVisibility(LinearLayout.INVISIBLE);
            }
        }
    });
}
}

When I launch the application it force closes. I debugged the application with the built-in Dev Tools application in the emulator, and see the following:

[2011-06-23 20:27:06 - ddms]null
java.lang.NullPointerException
    at com.android.ddmlib.Client.sendAndConsume(Client.java:572)
    at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
    at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
    at com.android.ddmlib.Client.getJdwpPacket(Client.java:671)
    at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
    at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

As well as a “Source not found.” error at:

ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2417

main.xml

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

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="My Application" android:gravity="center_horizontal"
android:textSize="25dp" android:background="#222" />

<LinearLayout 
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="  Server IP: " android:textSize="20dp" android:textColor="#0F0"
android:layout_weight="0.7" />
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="eg: 0.0.0.0" android:layout_weight="0.5" android:textSize="20dp"
android:id="@+id/loginIP" />
</LinearLayout>

<LinearLayout 
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Server Port: " android:textSize="20dp" android:textColor="#0F0"
android:layout_weight="0.7" />
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="eg: 1234" android:layout_weight="0.5" android:textSize="20dp"
android:id="@+id/loginPort" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:id="@+id/privacyLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Privacy Options" android:textSize="20dp" android:textColor="#0F0"
android:layout_weight="0.4" />
<ToggleButton android:layout_width="fill_parent" android:layout_height="wrap_content"
android:checked="false" android:layout_weight="0.6" android:textOff="Show Options"
android:textOn="Hide Options" android:id="@+id/privacyShow" />
</LinearLayout>

<LinearLayout 
android:orientation="vertical"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Username: " android:textColor="#0F0" android:textSize="15dp"
android:layout_weight="0.5" />
<EditText android:layout_width="fill_parent" android:layout_height="30dp"
android:id="@+id/privacyUsername" android:textSize="15dp" android:layout_weight="0.2" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Password: " android:textColor="#0F0" android:textSize="15dp"
android:layout_weight="0.5" />
<EditText android:layout_width="fill_parent" android:layout_height="30dp"
android:id="@+id/privacyPassword" android:textSize="15dp" android:layout_weight="0.2" />
</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-23T09:35:27+00:00Added an answer on May 23, 2026 at 9:35 am

    You can’t set the privBtn and privLay before the setContentView() is called. Move those two statements into your onCreate().

    public class My_Application extends Activity {
    
        public ToggleButton privBtn;
        public LinearLayout privLay;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            privBtn = (ToggleButton) findViewById(R.id.privacyShow);
            privLay = (LinearLayout) findViewById(R.id.privacyLayout);
    
            privBtn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    if(privBtn.isChecked()) {
                        privLay.setVisibility(LinearLayout.VISIBLE);
                    }
                    else {
                        privLay.setVisibility(LinearLayout.INVISIBLE);
                    }
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code similar to this in my application: class A { public: int
My Code: public class Contact { public string id{ get; set; } public string
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
Here is the first part of my controller code: public class ControlMController : Controller
Here is my code: class Soldier { public: Soldier(const string &name, const Gun &gun);
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
I have the following code in my ASP.NET project public sealed class IoC {
I have the following piece of code in my DataModel.cs class: public User ValidateUser(string
can somebody tell me why my code is not working? class Connection { public

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.