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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:35+00:00 2026-05-28T14:00:35+00:00

I just implemented the onClickListener. The App should switch between two layouts. On each

  • 0

I just implemented the onClickListener. The App should switch between two layouts. On each layout there is one button. After touching the button the Layout should change.

I searched trough various tutorials and documentary, my code should be correct, I simply don’t see the error. Eclipse also says the code is ok.

    package ralationship.v1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class RelationshipActivity extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    private Button OptionsButton;
    private Button SaveButton;

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

        SaveButton = (Button)findViewById(R.id.btnSave);
        OptionsButton = (Button)findViewById(R.id.btnOptions);
        OptionsButton.setOnClickListener(this);
        SaveButton.setOnClickListener(this);

    }

    public void onClick(View v) {
        if(v.getId() == (R.id.btnOptions)){
            setContentView(R.layout.options);
        }else if (v.getId() == (R.id.btnSave)){
            setContentView(R.layout.main);
        }

    }

}

Does anyone find an error?

//EDIT:

Here is the LogCat Report:

01-26 15:47:29.273: D/dalvikvm(336): GC_EXTERNAL_ALLOC freed 49K, 53% free 2549K/5379K, external 1625K/2137K, paused 67ms
01-26 15:47:29.453: D/AndroidRuntime(336): Shutting down VM
01-26 15:47:29.462: W/dalvikvm(336): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-26 15:47:29.473: E/AndroidRuntime(336): FATAL EXCEPTION: main
01-26 15:47:29.473: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{ralationship.v1/ralationship.v1.RelationshipActivity}: java.lang.NullPointerException
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.os.Looper.loop(Looper.java:123)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-26 15:47:29.473: E/AndroidRuntime(336):  at java.lang.reflect.Method.invokeNative(Native Method)
01-26 15:47:29.473: E/AndroidRuntime(336):  at java.lang.reflect.Method.invoke(Method.java:507)
01-26 15:47:29.473: E/AndroidRuntime(336):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-26 15:47:29.473: E/AndroidRuntime(336):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-26 15:47:29.473: E/AndroidRuntime(336):  at dalvik.system.NativeStart.main(Native Method)
01-26 15:47:29.473: E/AndroidRuntime(336): Caused by: java.lang.NullPointerException
01-26 15:47:29.473: E/AndroidRuntime(336):  at ralationship.v1.RelationshipActivity.onCreate(RelationshipActivity.java:22)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-26 15:47:29.473: E/AndroidRuntime(336):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-26 15:47:29.473: E/AndroidRuntime(336):  ... 11 more
01-26 15:47:33.633: I/Process(336): Sending signal. PID: 336 SIG: 9
  • 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-28T14:00:36+00:00Added an answer on May 28, 2026 at 2:00 pm

    I assume that your saveButton is in the R.layout.options layout? If so, it is not available to be found when your activity is first created, as you only have the content from R.layout.main. You should instead put the lines

    SaveButton = (Button)findViewById(R.id.btnSave);
    SaveButton.setOnClickListener(this);
    

    inside the onClickListener, after you have changed the layout with setContentLayout() to the correct layout.

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

Sidebar

Related Questions

I have just implemented WMD for my editor in an ASP.NET app. The problem
I am developing a Silverlight app using VS2008 Express. I have just implemented a
Just wondering if there was a nice (already implemented/documented) algorithm to do the following
Is there a way just like multidatatrigger behavior of WPF also implemented in Silverlight
I just implemented a remember me feature for a user login on a website.
I just implemented uploadify in my project, and I noticed what seems like an
We just implemented SVN usage at our office and the other dev and myself
I am currently building a web site and I just implemented SqlCacheDependency using LinqToSQL
i just wondering how the .net wcf application caching is implemented ?? It's single
i just want to know how the call hierarchy is implemented in eclipse IDE

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.