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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:17:44+00:00 2026-05-28T06:17:44+00:00

I am writing a test application which consists of: 2 buttons 1 Edittext 1

  • 0

I am writing a test application which consists of:
2 buttons
1 Edittext
1 Textview

The first button “Random” writes a random name both in the EditText box and the TextView
(I have a class called RandomName which returns a string with a random name)

The second button “print” writes whatver is in the EditText into the TextView

The program crashes when I run it and i can’t figure out why. Any help would be appreciated

Layout image here: http://img824.imageshack.us/img824/3046/rndname.jpg

public class RandomNameTesteActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}


public EditText nomeEdt = (EditText)findViewById(R.id.editText1);
public String nomeStr = nomeEdt.toString();
public TextView nomeTest = (TextView) findViewById(R.id.textView1);



public void onClick(View v) {
      // TODO Auto-generated method stub
      switch(v.getId())
      {
      case R.id.button1:
       //Put random name in EditText box and in TextView
          RandomName RndName = new RandomName();
          String rndNameStr = RndName.getName();  
          nomeTest.setText(rndNameStr);


      break;
      case R.id.button2:
       //Print whatever is in EditText box to TextView      
         nomeTest.setText(nomeStr);
      break;
      }
     } 

}

EDIT: CHANGED CODE TO THE FOLLOWING: (it doesnt crash anymore but it doesnt work, as in the buttons do nothing)

 public class RandomNameTesteActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
EditText nomeEdt;
TextView nomeTest;
String nomeStr;

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


    nomeEdt = (EditText)findViewById(R.id.editText1);
    nomeStr = nomeEdt.toString();
    nomeTest = (TextView) findViewById(R.id.textView1);
}






public void onClick(View v) {
      // TODO Auto-generated method stub
      switch(v.getId())
      {
      case R.id.button1:
       //Put random name in EditText box and in TextView
          RandomName RndName = new RandomName();
          String rndNameStr = RndName.getName();  
          nomeTest.setText(rndNameStr);


      break;
      case R.id.button2:
       //Print whatever is in EditText box to TextView      
         nomeTest.setText(nomeStr);
      break;
      }
     } 

}

  • 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-28T06:17:44+00:00Added an answer on May 28, 2026 at 6:17 am

    I believe the issue is with the following lines:

    public EditText nomeEdt = (EditText)findViewById(R.id.editText1);
    public String nomeStr = nomeEdt.toString();
    public TextView nomeTest = (TextView) findViewById(R.id.textView1);
    

    Change this to

    public EditText nomeEdt;
    public TextView nomeTest;
    
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    nomeEdt = (EditText)findViewById(R.id.editText1);
    nomeStr = nomeEdt.toString();
    nomeTest = (TextView) findViewById(R.id.textView1);
    }
    

    Try that and see if it fixes your issue. You can’t look up your other views until you have set the contentview.

    Also it helps if you post the stacktrace when asking a question

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

Sidebar

Related Questions

I am writing a test application which is controlling another computer. The test computer
I'm just writing a test application to work out how I can optimise searching
I have been writing Selenium test for web application and there seem to be
I'm writing an application and started to test my domain model entities. If I
I'm writing WatiN tests to test an Ajax web application and have come across
I'm fairly new to writing test cases and this will be my first major
I'm writing an application which can copy files on a network share. Usually the
I am developing a Math application which can be extended by writing python scripts.
I'm writing a C application which uses the pcap library to log how much
I am writing an application which tests email addresses, for one part of 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.