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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:30:54+00:00 2026-05-29T21:30:54+00:00

I used to have some experience with developing for android but I started up

  • 0

I used to have some experience with developing for android but I started up again after 6 months and forgot most of it. I am now using a macbook to do my developing on and had to set up Eclipse, the Android SDK and AVD all over again and I’m worried I messed something up.

When I start a new project with the default activity that displays “Hello World” on my screen the app runs fine. I then tried to put in two buttons that cause the text in a new TextView to change. But whenever I include the textView part I get a runtime error. When I comment it out, the app runs but obviously nothing happens. Based upon the tutorials I’ve been reading, this is the appropriate place and way to declare/create the textView but I can’t figure out what’s wrong. Any suggestions?

[Edit] I was messing around and found that I can make the mytext a field instead of a TextView and that worked. So in my onCreate(), I put

 mytext = (TextField)findViewById(R.id.TextView1);

but that doesn’t seem the right way to do things.

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class IntroActivity extends Activity {

     TextView myText = (TextView)findViewById(R.id.textView1);
   //i've tried this with final added on to it as well (recommended by eclipse)

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       setButtonClickListener();
    }

    private void setButtonClickListener() {
         Button button1 = (Button)findViewById(R.id.button1);
         Button button2 = (Button)findViewById(R.id.button2);

        button1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                myText.setText("Hello");
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            //  myText.setText("Goodbye");
            }
        });
            }



    }
  • 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-05-29T21:30:55+00:00Added an answer on May 29, 2026 at 9:30 pm

    This:

    TextView myText = (TextView)findViewById(R.id.textView1);
    

    should be separated. The declaration should be at the same place:

    private TextView myText;
    

    But the assignment should come only after setContentView:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myText = (TextView)findViewById(R.id.textView1);
    

    This is done since before setContentView, Dalvik doesn’t know from which layout to take the view that matchs the id R.id.textView1

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

Sidebar

Related Questions

I'm pretty new to Android development, but I have some experience with Java and
I have Used Dojo 1.0, but I have some version related questions: When will
I don't have a lot of experience developing web-based data entry software, but comparative
I have some experience with programming, but I have very little experience when it
I am a web-developer working in PHP. I have some limited experience with using
Today I started work on a small Java app. I have some experience with
I have some code used to send emails. It works on windows but when
I have some problem with my cfml website. I have used the below code
I have some WCF methods that are used to transmit information from a server
I have some methods that are used by several classes. My idea was to

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.