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

  • Home
  • SEARCH
  • 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 8955599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:35:49+00:00 2026-06-15T14:35:49+00:00

I want to use the value of a string variable in one class into

  • 0

I want to use the value of a string variable in one class into another…

But when i do so by creating an object in the calling class of the called class, i get the value as null.

I tried searching on the net and stack overflow and went through some similar answers,but the solutions to them were specific to those questions.So m asking again.

here are the 2 classes –

1st one is the class from which i want to use the variable.
class is – SelectedClass variable i want to use in another class – SelectedClass( a string)

2nd class is FEa.I want to use the value of the variable “SelectedClass” from the 1st class.

CLASS 1(SelectedClass)-

package com.attendance_trial.nirmik;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class SelectClass extends ListActivity 
{

public String classes2[] = {"FEa","FEb","SEa","SEb"};
String SelectedClass;

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    String SelectedClass = classes2[position];
    try
    {

        Class MyClass = Class.forName("com.attendance_trial.nirmik." + SelectedClass);
        Intent myintent = new Intent(SelectClass.this,MyClass);
        startActivity(myintent);

    }
    catch(ClassNotFoundException cnf)
    {
        cnf.printStackTrace();
    }


}

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    // TODO Auto-generated method stub
    setListAdapter(new ArrayAdapter<String>(SelectClass.this, android.R.layout.simple_list_item_1, classes2));
}   

}

CLASS 2 (FEa) –

package com.attendance_trial.nirmik;



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

public class FEa extends Activity implements View.OnClickListener
{

SelectClass sc = new SelectClass();

//Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,bSend;
Button bSend;
TextView tvDisp;
String acc="";


@Override
protected void onCreate(Bundle savedInstanceState)
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fea);
    initialise();


}



private void initialise()//initialise all buttons etc
{

    bSend = (Button) findViewById (R.id.BtnSendMsg);
    bSend.setOnClickListener(this);
    tvDisp=(TextView) findViewById (R.id.TxtViewDisplay);

}





public void onButtonClick(View v)
{
    // TODO Auto-generated method stub


        Button theButton = (Button)v;
        String chk = theButton.getText().toString();
        if(chk.contentEquals("1")||chk.contentEquals("2")||chk.contentEquals("3")||chk.contentEquals("4")||chk.contentEquals("5")
                ||chk.contentEquals("6")||chk.contentEquals("7")||chk.contentEquals("8")||chk.contentEquals("9"))
        {
        acc = acc + "0" + chk;
        }
        else
        {
            acc =  acc +chk;
        }
        tvDisp.setText("String Is:" + acc);


}//method end



@Override
public void onClick(View v2) 
{
    // TODO Auto-generated method stub
    int retid = v2.getId();
    if(retid == R.id.BtnSendMsg ) //send button clicked
    {

        String msg = sc.SelectedClass + "2210"+ acc;
                Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.setType("plain/text");
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg);
                startActivity(emailIntent);
    }

}

}//main end

  • 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-15T14:35:50+00:00Added an answer on June 15, 2026 at 2:35 pm

    What you are doing is totally wrong.

    You are not supposed to manually create objects from a class which extends an Activity. AKA you should never do this: SelectClass sc = new SelectClass();.
    You have to tell the Android OS to do it for you by using:

    Intent intent = new Intent(this, YourActivity.class);
    startActivity(intent);
    

    Now if you want to send a String from SelectClass to FEa, you can send it with the intent like this:

    Intent intent = new Intent(this, YourActivity.class);
    intent.putExtra(EXTRA_MESSAGE_KEY, yourString);
    startActivity(intent);
    

    And in your second Activity, in onCreate():

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // Get the string from the intent
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
    
    }
    

    You should check developer.android.com to make yourself an idea how to program in Android. Bare in mind, Android programming is not Java programming.

    How to start a new Activity, from the developers site here.

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

Sidebar

Related Questions

I am developing one web application. In that i want to use variable's value
When we want to modify some value in one object we may use two
I want to use regex to split some string like this @key='value' to key
I want to use a particular string found in the Values folder into normal
I want to use a variable value in exec where i don't need to
If I want to get to a value in vector I can use two
I need to use the value of a variable as one of my fields
I'm using MSVC++, and I want to use the special value INFINITY in my
I have a combobox whose value I want to use with a SQL WHERE
I want preserve original value of target field and use json_decode to use following

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.