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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:57:22+00:00 2026-05-30T00:57:22+00:00

I am relatively new to the android game and I am having an issue

  • 0

I am relatively new to the android game and I am having an issue with my app crashing whenever I call a function from a second java class.

this is my main JAVA file:

    package mashuda.tools.calculator;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class CalculatorActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Drawinterface layout = new Drawinterface();


        setContentView(layout.drawit());


    }

}

and it is calling this code:

 package mashuda.tools.calculator;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Drawinterface extends Activity { 
    /** Called when the activity is first created. 
     * @return */


        TableLayout drawit(){

            TableLayout maintable = new TableLayout(this);

            maintable.setStretchAllColumns(true);
            maintable.setShrinkAllColumns(true);

            TableRow banner = new TableRow(this);
            banner.setGravity(Gravity.CENTER_HORIZONTAL);

            TableRow rowOutput = new TableRow(this);
            TableRow rowSeven = new TableRow(this);
            TableRow rowFour = new TableRow(this);
            TableRow rowOne = new TableRow(this);
            TableRow rowZero = new TableRow(this);


            //answer box
            TextView answer = new TextView(this);
            answer.setText("ANSWER");

            answer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);

            answer.setBackgroundColor(-1);

            answer.setGravity(Gravity.RIGHT);
            answer.setTypeface(Typeface.SERIF);

            TableRow.LayoutParams params = new TableRow.LayoutParams();
            params.span = 5;

            //loads answer bar
            rowOutput.addView(answer, params);
            //first column
            //creates 7 key
            Button sevenkey = new Button(this);
            sevenkey.setText("7");
            sevenkey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates 8 key
            Button eightkey = new Button(this);
            eightkey.setText("8");
            eightkey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates 9 key
            Button ninekey = new Button(this);
            ninekey.setText("9");
            ninekey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates division key
            Button dividekey = new Button(this);
            dividekey.setText("/");
            dividekey.setTypeface(Typeface.DEFAULT_BOLD);

            // loads top row
            rowSeven.addView(sevenkey);
            rowSeven.addView(eightkey);
            rowSeven.addView(ninekey);
            rowSeven.addView(dividekey);

            //creates 4 key
            Button fourkey = new Button(this);
            fourkey.setText("4");
            fourkey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates 5 key
            Button fivekey = new Button(this);
            fivekey.setText("5");
            fivekey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates 6 key
            Button sixkey = new Button(this);
            sixkey.setText("6");
            sixkey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates multiplication key
            Button multiplykey = new Button(this);
            multiplykey.setText("X");
            multiplykey.setTypeface(Typeface.DEFAULT_BOLD);

            // loads keys into second row
            rowFour.addView(fourkey);
            rowFour.addView(fivekey);
            rowFour.addView(sixkey);
            rowFour.addView(multiplykey);


            //creates 1 key
            Button onekey = new Button(this);
            onekey.setText("1");
            onekey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates 2 key
            Button twokey = new Button(this);
            twokey.setText("2");
            twokey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates 3 key
            Button threekey = new Button(this);
            threekey.setText("3");
            threekey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates add key
            Button addkey = new Button(this);
            addkey.setText("+");
            addkey.setTypeface(Typeface.DEFAULT_BOLD);

            // loads keys into third row
            rowOne.addView(onekey);
            rowOne.addView(twokey);
            rowOne.addView(threekey);
            rowOne.addView(addkey);

            //creates 0 key
            Button zerokey = new Button(this);
            zerokey.setText("0");
            zerokey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates . key
            Button decimalkey = new Button(this);
            decimalkey.setText(".");
            decimalkey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates - key
            Button negativekey = new Button(this);
            negativekey.setText("+/-");
            negativekey.setTypeface(Typeface.DEFAULT_BOLD);

            // creates equals key
            Button equalskey = new Button(this);
            equalskey.setText("=");
            equalskey.setTypeface(Typeface.DEFAULT_BOLD);

            // loads keys into fourth row
            rowZero.addView(zerokey);
            rowZero.addView(decimalkey);
            rowZero.addView(negativekey);
            rowZero.addView(equalskey);

            // loads rows into table
            maintable.addView(rowOutput); 
            maintable.addView(rowSeven); 
            maintable.addView(rowFour);
            maintable.addView(rowOne);
            maintable.addView(rowZero); 

            //sets view as maintable
            return (maintable);

}
}

I did add the second file to the android manifest.
and my compiler(eclipse) does not detect any errors.
Any help would be greatly appreciated

  • 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-30T00:57:24+00:00Added an answer on May 30, 2026 at 12:57 am

    Instead of creating your TableLayout programatically use an xml resource file.

    Here is a tutorial on this: http://huuah.com/using-tablelayout-on-android/

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

Sidebar

Related Questions

I'm relatively new to Android programming, and am having a problem with inflation. I'm
I'm still relatively new to Java and Android development, so I'm still unfamiliar with
I'm relatively new to java and android development so sorry if this is a
I'm relatively new to Java, eclipse and android so this could be a completely
I relatively new to using Eclipse with the Android SDK. Whenever I encounter an
I'm relatively new to Android development and Java (learning both simultaneously sort of...). My
I'm relatively new to java and android, in my android application I need to
I am relatively a new Android developer and I am not able to understand
I am a relatively new Android programmer and I was wondering how you could
Hi I'm relatively new to Android programming but I would be grateful of some

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.