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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:02:32+00:00 2026-06-18T02:02:32+00:00

I made just one activity that opens another activity . Everything was working right

  • 0

I made just one activity that opens another activity. Everything was working right until i setted up onClickListener. Now my app force closes when it launch. Without these two lines application launches correctly:

BUeasycounter.setOnClickListener(this);
BUrps.setOnClickListener(this);

Here is my full source:

package com.dano.learning;

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

public class Menu extends Activity implements View.OnClickListener{

    Button BUeasycounter;
    Button BUrps;
    @Override
    protected void onCreate(Bundle MyBundle) {
        super.onCreate(MyBundle);
        setContentView(R.layout.activity_main);
        initializeVars();
// next 2 lines cause the problem
        BUeasycounter.setOnClickListener(this);
        BUrps.setOnClickListener(this);
    }
    public void initializeVars(){
        Button BUeasycounter= (Button) findViewById(R.id.BUeasycounter);
        Button BUrps = (Button) findViewById(R.id.BUrps);
    }

    public void onClick(View v) {
        switch (v.getId()){
            case R.id.BUeasycounter:
                Intent openEasyCounter = new Intent("com.dano.learning.EASYCOUNTER");
                startActivity(openEasyCounter);
                break;
            case R.id.BUrps:
                Intent openRPS = new Intent("com.dano.learning.EASYCOUNTER");
                startActivity(openRPS);
                break;
        };

    }
}

Maybe i just typed something wrong but I cant find mistake in my source for more than two days. Thank you for your help.

  • 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-18T02:02:33+00:00Added an answer on June 18, 2026 at 2:02 am

    There is no exception stack in question, but based on code I see one issue is:

        Button BUeasycounter;
        Button BUrps;
    

    Both are pointing to null which could be throwing NullPointerException when you do

        BUeasycounter.setOnClickListener(this);
        BUrps.setOnClickListener(this);
    

    Remove new variable in initializeVars method.

    Example:

    public void initializeVars(){
              BUeasycounter= (Button) findViewById(R.id.BUeasycounter);
              BUrps = (Button) findViewById(R.id.BUrps);
        }
    

    Note: Java naming convention suggest that use small letter as first letter for variable name.

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

Sidebar

Related Questions

I am working on an android app that has two activities. One is the
I have an image which is just made of one color ? (it could
Say you just want to get rid of the changes you've made to one
I need to launch an app I've made just after login, before anything else
I just made my first website , and I notice that the elements start
I was just made aware of a bug I introduced, the thing that surprised
well, I just made such a hello world non-Flex app in FlashDevelop and packaged
I made a password generator app that works well, but I want to update
Nowadays we tend to split the amount of work made in just one page
I just got done writing an Android Activity that allows other Activities to call

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.