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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:10:03+00:00 2026-06-07T05:10:03+00:00

Ok guys, I have a button in android that i’m trying to use to

  • 0

Ok guys, I have a button in android that i’m trying to use to update 8 EditText Views with different random numbers. Everything works up until I click the button. It appears I am missing a resource according to the debugger, but I’m not sure what. I’ve tried several different ways of implementing the button. Here is what I have after looking at several posts.

import java.util.Random;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MyCharNewChar extends MyCharActivity {


private OnClickListener randomButtonListener = new OnClickListener(){
    public void onClick(View v) {
        //Button creates a set of random numbers and updates the values
        //of the EditText views.

        Random rand = new Random();
        int STR = 1 + rand.nextInt(12);
        int AGI = 1 + rand.nextInt(12);
        int DEX = 1 + rand.nextInt(12);
        int WIS = 1 + rand.nextInt(12);
        int INT = 1 + rand.nextInt(12);
        int CON = 1 + rand.nextInt(12);
        int HP = 1 + rand.nextInt(20);
        int AC = 1 + rand.nextInt(6);

        EditText str = (EditText) findViewById(R.id.str);
        str.setText(STR);
        EditText agi = (EditText) findViewById(R.id.agi);
        agi.setText(AGI);
        EditText dex = (EditText) findViewById(R.id.dex);
        dex.setText(DEX);
        EditText wis = (EditText) findViewById(R.id.wis);
        wis.setText(WIS);
        EditText intel = (EditText) findViewById(R.id.intel);
        intel.setText(INT);
        EditText con = (EditText) findViewById(R.id.con);
        con.setText(CON);
        EditText hp = (EditText) findViewById(R.id.baseHP);
        hp.setText(HP);
        EditText ac = (EditText) findViewById(R.id.baseAC);
        ac.setText(AC);
        }
    };

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newchar);
    Button randomButton = (Button) findViewById(R.id.randomButton);
    randomButton.setOnClickListener(randomButtonListener);
}


}

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayoutNew1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background" >
<TextView 
    android:id="@+id/newCharLabel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/new_character_screen"
    android:textSize="24dp"
    android:textColor="@color/splash"
    android:textStyle="bold"
    android:gravity="center"/>
<TextView
    android:id="@+id/nameLabel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/nameLabel"
    android:textSize="18dp"
    android:textColor="@color/splash"/>
<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName" >
    <requestFocus />
</EditText>
<TableLayout
    android:id="@+id/statsLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
    <TableRow
        android:id="@+id/tableRow01"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp">
        <TextView
            android:id="@+id/strLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/strLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>

        <EditText
            android:id="@+id/str"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number" />
        <TextView
            android:id="@+id/agiLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/agiLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText
            android:id="@+id/agi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
        <TextView
            android:id="@+id/dexLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/dexLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText
            android:id="@+id/dex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
    </TableRow>
    <TableRow
        android:id="@+id/tableRow02"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp">
        <TextView 
            android:id="@+id/intLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/intLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText
            android:id="@+id/intel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
        <TextView 
            android:id="@+id/wisLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/wisLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText
            android:id="@+id/wis"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
        <TextView
            android:id="@+id/conLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/conLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText
            android:id="@+id/con"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
    </TableRow>
</TableLayout>
    <LinearLayout
        android:id="@+id/linearlayoutNew02"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:gravity="center">
        <TextView
            android:id="@+id/baseHPLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hpLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText 
            android:id="@+id/baseHP"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
        <TextView
            android:id="@+id/baseACLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/acLabel"
            android:textSize="18dp"
            android:textColor="@color/splash"/>
        <EditText
            android:id="@+id/baseAC"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="3"
            android:inputType="number"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/linearlayoutNew03"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


    <Button
        android:id="@+id/randomButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/randomButton"
        android:textSize="16dp"
        android:clickable="true"/>

    </LinearLayout>
</LinearLayout>

I have also tried setting the onClick in xml to setup a specific onClick method. Still the same error so I must have a problem elsewhere. Any suggestions would be great!

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

    you are trying to setText as int,and it must be String.

     str.setText(STR+" ");
    

    or

     str.setText(String.valueof(STR));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have a little button functionality that is not erring, but also
Guys I have an activity which has a home button, when the button is
HI Guys I Have A jar File Named Column Reader. I am trying to
Android: guys i want to detect which button is clicked by the user. The
guys i am working on android 2.2.I have a situation where when the user
Hi guys i have a problem with the browsers back button when i click
Hello guys I have 1675 line Code. Want to when user click button textbox.text
Good day to you guys I have an application that has a UITabBarController for
hi guys i have a weird prob here.. i have this dropdownlist where different
I am creating an application that saves GPS coordinates; I have created a button

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.