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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:57:13+00:00 2026-06-01T19:57:13+00:00

I have a main class in Android java project where all functions are defined.

  • 0

I have a main class in Android java project where all functions are defined. Then I have 2 other classes that extend the main class and implement Runnable.

  • main class: All main functions
  • class 2: I use all main functions and have a static variable X which I modify in file 2.
  • class 3: I use all main functions and have a static variable Y which I modify in file 3.

In the main class, I start 2 threads: one for Class2, and one for Class3.

When I try to call Class2.X from the main class, it is always null no matter what. I have tried volatile, synchronized(thread), getvalue(), etc. but it is not working.

What should I do to read the values of Class2.X such that it is not null from the main class?

Here is the code:

Thread t = new Thread(new Functionss(mRgbImage));
t.start();
Thread t2 = new Thread(new Functionss_2(mRgbImage));
t2.start();

if(boolean_variable)
{
    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Bitmap final_added =addition(mRgbImage2, mRgbImage3);                 
    mImageView.setImageBitmap(final_added);

mRgbImage2 and mRgbImage3 are the static volatile variables.

In fact, I think it is not a problem of variables because when i use an image in the main class and modify it, and then execute mImageView.setImageBitmap(initial_image) i am still getting a black screen on my android phone.

I have noted the following in the logcat:

Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40a34d28

If I remove the threads, I don’t get this error.

Any 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-01T19:57:15+00:00Added an answer on June 1, 2026 at 7:57 pm

    I suspect that your threads are never executing the assignment statement or are assigning a different value or something. Maybe putting some log messages or debugging your application and putting a break point at the assignment would help.

    If you had something like:

    public class MainClass {
        Class2 class2 = new Thread(new Class2());
        class2.start();
        class2.join();
        // Class2.value will == 10 here
    }
    

    and then:

    public class Class2 implements Runnable {
        public static volatile int value;
        public void run() {
           ...
           this.value = 10;
           ...
        }
    }
    

    Then after the assignment happens in Class2 then the value will have been updated. This is obviously a simple example and I suspect the Class2 thread has not actually finished in your code, but as long as the assignment has been reached then value will have been changed. Again, log messages or debugger would help here.

    It would be better to have something like the following pattern:

    public class Class2 implements Runnable {
        private volatile int value;
        public void run() {
           ...
           this.value = 10;
           ...
        }
        public int getValue() {
            return this.value;
        }
    }
    

    So then MainClass can access the value from Class2 and Class3 without confusion. Notice that you still need the volatile keyword there because the value is being get/set from different threads.

    Hope something here helps. If you edit your question with more details I may be able to help more.

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

Sidebar

Related Questions

I have two projects, my main android application and another test project that runs
I have a main class in a program that launches another class that handles
I have a small Java test app in Netbeans where the main() class reads
i have any div for show details of project ( class main ). now
I have an Android project that depends on an android library (apklib) project. The
I have main activity which call other object, for example GPS class. This GPS
I have created a custom class for my Android project called Sounds I want
I have a main class(which is basically a netbeans form;drag and drop) from where
I have a Main class and a HelloWorld class. I have created a button
I have a question about the 'Event Dispatch Thread'. I have a Main class

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.