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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:20:06+00:00 2026-06-13T06:20:06+00:00

I built two activities and the MainActivity is passing some variables to the activity

  • 0

I built two activities and the MainActivity is passing some variables to the activity “Calculation”. This works as intended and the variables are submitted and received correctly. I now want to create the integer “size_int” depending on the values of the intent “size”. The problem occurs in this line:

    debug1.setText(size_int);

Eclipse tells me that I should create a local variable with the name “size_int”. I do not understand why “size_int” can not be used in this line because it has been defined in the if statement before. Do you have any ideas on that? I assume it has something to do that the variable “size_int” is being defined in the if statement but I am not sure.

Here is the full code:

package com.example.eggtimer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Calculation extends Activity {



    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calculation);


        // get Intents (Size, Temperature and yolk from Main Activity)
        String size = getIntent().getExtras().getString("size");
        String temperature = getIntent().getExtras().getString("temperature");
        String yolk = getIntent().getExtras().getString("yolk");

        if (size.equals("Small")) {
            int size_int = 30;
        }



        // Debug Variables
        TextView debug1 = (TextView) findViewById(R.id.textViewDebug1);


        debug1.setText(size_int);

    }



}
  • 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-13T06:20:07+00:00Added an answer on June 13, 2026 at 6:20 am

    Change like below. This is because if you declare inside the braces, the scope is restricted, so you need to increase scope by declaring outside

    int size_int = 0; 
    if (size.equals("Small")) {
                size_int = 30;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables built like this (this is just a simplified and non-proprietary
I have two activities that both contain an identical context menu built programmatically using
Hello i build a small app using Android, in this app i built two
On page three of this OpenCL reference sheet (broken link) there are two built
My application is built in two sections. A C# executable which is the front
I have two app icons built-in (free and premium), is it possible to replace
I have two projects A and B both are built differently, but the jars
I have built a custom hashmap using two arrays. One contains keys another values.
I'm currently working on two projects simultaneously: My main project (built with maven) A
I have two webapps, that are built together and respectively provide a client and

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.