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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:11:46+00:00 2026-05-31T04:11:46+00:00

I did look at all the suggestions which I could get my hand on

  • 0

I did look at all the suggestions which I could get my hand on but those corrections were already there in my code..please have a look at this.
Basically I am trying to call another activity from the main activity after the click of an button.

//Here's the code of my main activity named Test1Activity:
public class Test1Activity extends Activity {

private int clicked=0;
public static final String pass="com.sanjay.test1._clicked";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
Button button1=(Button) findViewById(R.id.button1);
Button button2=(Button) findViewById(R.id.button2);

button1.setId(1);
button2.setId(2);

button1.setOnClickListener( new OnClickListener() {
    public void onClick(View v) {
      int id = v.getId();
      clicked=id;

    }
});
button1.setOnClickListener( new OnClickListener() {
    public void onClick(View v) {
      int id = v.getId();
      clicked=id;
    }
});Intent i = new Intent(this,Sanjay.class);i.putExtra(pass,clicked);startActivity(i);
}

}

//Now my other Activity code : 
public class Sanjay extends Activity {

/** Called when the activity is first created. */
int a;
TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);

    text=(TextView) findViewById(R.id.text);
    a=getIntent().getExtras().getInt(Test1Activity.pass);

    text.setText(a);
    // TODO Auto-generated method stub
}
}


//And my xml file of the second activity layout resource.
//I am not adding the main.xml as the program runs fine if I pass the startactivity(i) and the intent lines as comments.
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>
  • 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-31T04:11:48+00:00Added an answer on May 31, 2026 at 4:11 am

    You cannot call setText with an int, as in this case it expects the int to be an ID of a resource.

    Instead, make it a string:

    text.setText("" + a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I did gave a look at this one. But I didn't
First of, I'm fairly new to Qt. I did look for the answer but
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
I noticed that there were some threads with similar questions, and I did look
I'm not sure what I did, because this used to work fine, but all
Background First of all, I did look elsewhere for a solution and found this
Did any one have luck recently register Visual studio 2008 express C# product? Look
Did you ever have the following situation: you need to store information, but a
Did anyone tried to customize the window in which the quicktime is playing video?
Did about 30 minutes worth of searching, found lots of relevant info, but none

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.