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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:18:41+00:00 2026-06-11T14:18:41+00:00

In this method i set mode to 1; bTouch.setOnClickListener(new View.OnClickListener() { public void onClick(View

  • 0

In this method i set mode to 1;

bTouch.setOnClickListener(new View.OnClickListener() {     
  public void onClick(View v) {
    mode1=1;
      Intent startGame = new Intent(
        "com.example.mygame.GFXSurface");
        startActivity(startGame);
  }
});

when i call that mode in other class in onTouch method returns 0

public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
    GameSurface gamesurface = new GameSurface(this);
    Mode mode2 = new Mode();
    mode= mode2.mode1; 
        if (mode == 1){        // this should be 1 but is 0
            x = event.getX();
            y = event.getY();

Anyone know the solution on how to do that?

  • 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-11T14:18:42+00:00Added an answer on June 11, 2026 at 2:18 pm

    No, mode1 values is not 1, It should be 0.

    Just look at these two code lines..

    Mode mode2 = new Mode();
    mode= mode2.mode1; 
    

    Now from 1 code line Mode mode2 = new Mode();

    you are creating a new Class Mode object mode2.

    As per the class object initializing rules you are allocated a memory for a new Mode class. So all its member variables and fields are initializing to with new mwmory.

    Now come on code line 2

    mode = mode2.mode1; 
    

    you are accessing mode1 member field of newly created class Mode with object mode2.

    So how it can hold the old value 1? (Think again)

    Now how can you access this value in other class?
    

    Either make a member field mode1 as a static and directly access the field with class Name,

    like, Mode.mode1

    Or use the same object for retrieving (get) value of mode1 from which you set the value for mode1.

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

Sidebar

Related Questions

Till this moment I used this method to invoke: public string AddText { set
I have a button and onclick is set to this method which should display
I have this loop method to display a ViewPager and I set an OnClickListener
I ran this sql query in my database: update payments set method = 'paysafecard'
In Java we use System.setProperty() method to set some system properties. According to this
In JavaScript, you can set a variable equal to a method like this: variable
This is my activity oncreate() method. I set a positive button ok with a
This method right below reverses a doubly linked list with n elements. I dont
This method works as expected - it creates a JTree with a root node
This method that draws my tiles seems to be quite slow, Im not sure

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.