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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:40:10+00:00 2026-06-14T09:40:10+00:00

This is strange, maybe someone can help with this. I have two classes and

  • 0

This is strange, maybe someone can help with this. I have two classes and when I try to access variable from main class, value is always 0.0

MAIN CLASS

public class MainActivity extends Activity {
  public float angleCurrent;
  - do something whith angleCurrent
  //System.out.println(angleCurrent);    - I get right values
}

SECOND CLASS

public class SecondClass extends ImageView {
  public float curAngle = new MainActivity().angleCurrent;
  //System.out.println(curAngle);   - I get 0.0 all the time
}

Code is just illustration.

  • 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-14T09:40:11+00:00Added an answer on June 14, 2026 at 9:40 am

    There are a couple big issues at play here. First, why the behavior is occurring:

    You are not accessing the variable from the first MainActivity instance inside of SecondClass, you have created a new second instance of MainActivity, so you are getting access to a different variable than the original.

    Now, the second issue surrounds the correct way to do this in Android. You should NEVER directly instantiate Activity instances. It is also not good practice to pass references to an Activity around any more than the framework already does. If your Activity needs to pass some information to your custom ImageView, you should create a method on your ImageView that you can use for the Activity to pass the value forward (i.e. SecondClass.setCurrentAngle(angleCurrent))

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

Sidebar

Related Questions

This is very strange, maybe someone can explain what's happening, or this is a
I have this strange behavior in my JSP page: I have two Integer variables
I have a question about strange return sizes when calling GetUserNameEx(). Maybe someone has
I'm getting this strange error message when trying to clone or pull from git.
I have this strange problem. I am retrieving twitters and it works on the
Could someone explain this (strange) behavior? Why is the length in the first example
I have this strange error, When I call $element_attrs = $element -> attributes(); I
I have this strange issue, and im dealing with it for more than 8
Can someone explain why the console acts this way? I posted this question once,
everyone, i found this strange problem ( maybe it is a feature ) this

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.