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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:39:38+00:00 2026-05-21T05:39:38+00:00

After being pointed in the right direction to learn about views and layouts I

  • 0

After being pointed in the right direction to learn about views and layouts I was able to make a calculator that I thought looked pretty nice. I added some very basic code to it that is far from elegant but i wanted to get my feat wet with making a simple app. So far it only says the process has stopped and to try again. I am 100 percent positive that it is my code and not my ui making this happen. I was able to make a basic button counter before with 1 button but now with 15 buttons I think I screwed up.

Here is the code for the calculator called hellocats(i was following a basic tutorial and kept on adding)

package com.hellocats;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class hellokatz extends Activity {
    /** Called when the activity is first created. */



int numbermover = 0;
int[] numbers ={0,0};

String sign = "+";
int answer;




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

   final Button button0 = (Button)findViewById(R.id.button0);
   final Button button1 = (Button)findViewById(R.id.button1);
   final Button button2 = (Button)findViewById(R.id.button2);
   final Button button3 = (Button)findViewById(R.id.button3);
   final Button button4 = (Button)findViewById(R.id.button4);
   final Button button5 = (Button)findViewById(R.id.button5);
   final Button button6 = (Button)findViewById(R.id.button6);
   final Button button7 = (Button)findViewById(R.id.button7);
   final Button button8 = (Button)findViewById(R.id.button8);
   final Button button9 = (Button)findViewById(R.id.button9);

   final Button addbutton = (Button)findViewById(R.id.buttonadd);
   final Button subbutton = (Button)findViewById(R.id.buttonsub);
   final Button mulbutton = (Button)findViewById(R.id.buttonmul);
   final Button divbutton = (Button)findViewById(R.id.buttondiv);
   final Button equalsbutton = (Button)findViewById(R.id.buttonequals);

   final  EditText num1 = (EditText)findViewById(R.id.num1);
   final EditText mysign = (EditText)findViewById(R.id.sign);
   final  EditText num2 = (EditText)findViewById(R.id.num2);
   final  EditText answer = (EditText)findViewById(R.id.answer);


    num1.setText(numbers[0]);
    num2.setText(numbers[1]);
    mysign.setText(sign);


    button0.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 0;

        }
    });
       button1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 1;

        }
    });
       button2.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 2;

        }
    });
       button3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 3;

        }
    });
       button4.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 4;

        }
    });
       button5.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 5;

        }
    });
       button6.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 6;

        }
    });
       button7.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 7;

        }
    });
       button8.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 8;

        }
    });
       button9.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            numbers[numbermover] = 9;

        }
       });


}
}

Here is the layout file main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">
    <TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:text="  1   " android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  2   " android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  3   " android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  4   " android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  5   " android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  6   " android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  7   " android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>
    <TableRow android:id="@+id/tableRow2" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:text="  8   " android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  9   " android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  0   " android:id="@+id/button0" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>
    <TableRow android:id="@+id/tableRow3" android:layout_height="wrap_content" android:layout_width="match_parent">
        <Button android:text="  +   " android:id="@+id/buttonadd" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  -   " android:id="@+id/buttonsub" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  X   " android:id="@+id/buttonmul" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  /   " android:id="@+id/buttondiv" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="  =   " android:id="@+id/buttonequals" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>
    <TableRow android:id="@+id/tableRow4" android:layout_height="wrap_content" android:layout_width="match_parent">
        <EditText android:text="      " android:id="@+id/num1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
        <EditText android:text="      " android:id="@+id/sign" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
        <EditText android:text="      " android:id="@+id/num2" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
        <EditText android:text="  =   " android:id="@+id/equals" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
        <EditText android:text="      " android:id="@+id/answer" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
    </TableRow>
</LinearLayout>  

What did I do incorrectly in my java file and how can I fix it and learn from it?

Thank you:Aslo i am very new to your website and so far cannot figure out for the life of me how to post the main.xml file. I tried CTRL+K and CTRL+V to past it in and so far nothing

  • 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-21T05:39:39+00:00Added an answer on May 21, 2026 at 5:39 am

    Your array int[] numbers ={0,0}; is of type int.

    EditText accepts a CharSequence so my guess is that it throws an error at the line below:

    num1.setText(numbers[0]);
    

    Try something like (if it works, update then num2 and mysign):

    num1.setText(Integer.toString(numbers[0]));
    

    As GrAnd pointed out, setText also accepts an int that represents a resourceId. It couldnt find the string with id 0 and threw the error.

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

Sidebar

Related Questions

I'm trying to write a decorator that 'refreshes' after being called, but where the
Edit2: After finally being able to profile the two against each other, it appears
What I am after is being able to have my application, in dev mode,
I am looking for a working example of multiprocessing.Queue after being pointed to it
After being pointed to using glBitmap() and this very good tutorial/explanation of its usage
After being stumped by an earlier quesiton: SO google-analytics-domain-data-without-filtering I've been experimenting with a
After being blown away by the greatness of irb and rails console, I am
I want to display the column 'name' after being found from the table mytest.
I have implemented the following set up (after being requested): slideshow of images changing,
Im having trouble understanding class relationships after being asked to research it further, would

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.