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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:13:35+00:00 2026-06-04T05:13:35+00:00

There are two classes. MainActivity, in which i set the view, and ClassX from

  • 0

There are two classes. MainActivity, in which i set the view, and ClassX from which i want to update a view in MainActivity. ClassX is an AsyncTask called from MainActivity, if that’s relevant.

What i want to do is to change the text of a view called mainTextLog. I’ve declared a global TextView variable, and in the onCreate() method i set it to the view using findViewById().

private TextView logger;

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

    logger = (TextView) findViewById(R.id.mainTextLog);

}

By now i should be able to change the text from onCreate(), and i can. But since i want to change it from another class (ClassX) i need to create a method for it:

public void setLogText(String text) {
    logger.setText(text);
}

But it doesn’t work. I’ve tried making logger and the setLogText() method static, but it still doesn’t work. The app just crashes.

It’s probably pretty easy, but i’m out of ideas.

  • 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-04T05:13:37+00:00Added an answer on June 4, 2026 at 5:13 am

    If you are using an AsyncTask you need to set the value in either onProgressUpdate or in onPostExecute.

    You really should read the documentation for AsyncTasks

    You CANNOT update the UI from the doInBackground method as it is not run in the UI thread and will give you an exception.

    Also, you should post the exception you are getting when the application crashes so we have a better idea what the problem is. But I’d guess you are trying to update the text from the wrong thread.

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

Sidebar

Related Questions

There are two classes: A and B . There are algorithms for converting from
I want to use these two classes from lucene - import org.apache.lucene.analysis.snowball.*; import org.apache.lucene.analysis.PorterStemmer;
There are two base classes have same function name. I want to inherit both
There are two classes. Class B dervied from A. class A { } class
In my program there are only two classes one is Parent ,which is an
Within my app there are two view-classes: UIViewA and UIViewB. In the Storyboard I
There are two classes, let's call them X and O. A number of elements
http://pastebin.com/1btVw8Cb There are two classes in the above code. So above is my code
I have a problem. There are two classes: struct Base { Base* retain() {
My program involves drawing triangles where i click them. There are two classes, Ecad

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.