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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:10:54+00:00 2026-05-25T10:10:54+00:00

Basically my question is quite common. However I have google and research all the

  • 0

Basically my question is quite common. However I have google and research all the possible solutions but to no avail thus asking on SO to resolve it.

My question is why when I findViewById for a textview, i got a null when returning back. Below is my activity and the XML file.

Activity:

public class Chicken extends ListActivity {

private TextView dishName;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] chicken = getResources().getStringArray(R.array.chicken_array);
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
            chicken));

    dishName = (TextView) findViewById(R.id.TextView02);
    Log.w("test", "ok " + dishName); // returns null

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Toast.makeText(getApplicationContext(),
                    ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
}

XML:

<?xml version="1.0" encoding="UTF-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/LinearLayout1"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:padding="5dp">
    <TabWidget android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" android:id="@android:id/tabs"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
    <FrameLayout android:layout_alignParentLeft="true"
        android:layout_below="@android:id/tabs" android:id="@android:id/tabcontent"
        android:layout_width="185dp" android:layout_height="fill_parent"
        android:padding="5dp">
    </FrameLayout>
    <RelativeLayout android:layout_toRightOf="@android:id/tabcontent"
        android:id="@+id/relativeLayout1" android:layout_height="fill_parent"
        android:layout_alignTop="@android:id/tabcontent"
        android:layout_gravity="right" android:layout_width="115dp"
        android:background="@drawable/brown" android:gravity="fill_vertical"
        android:layout_alignRight="@android:id/tabs">
        <TextView android:textColor="#000000" android:layout_height="wrap_content"
            android:text="@string/order" android:paddingTop="3dp"
            android:layout_width="wrap_content" android:id="@+id/textView1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"></TextView>
        <Button android:layout_height="wrap_content"
            android:layout_width="105dp" android:text="Send" android:id="@+id/button1"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"></Button>
        <FrameLayout android:id="@+id/frameLayout1"
            android:padding="3dp" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_below="@+id/textView1"
            android:layout_alignLeft="@+id/button1" android:layout_above="@+id/button1"
            android:layout_alignParentRight="true">
            <ScrollView android:id="@+id/ScrollView01"
                android:layout_width="wrap_content" android:layout_height="wrap_content">
                <TableLayout android:id="@+id/tableLayout01"
                    android:shrinkColumns="1" android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:layout_below="@+id/textView1"
                    android:layout_alignLeft="@+id/button1">
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow01">
                        <TextView android:id="@+id/TextView01"
                            android:textColor="#000000" android:layout_width="25dp"
                            android:layout_height="wrap_content" android:text="x1"></TextView>
                        <TextView android:id="@+id/TextView02" android:text="chicken"
                            android:textColor="#000000" android:layout_width="wrap_content"
                            android:layout_height="wrap_content"></TextView>
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow02">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow03">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow04">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow05">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow06">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow07">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow08">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow09">
                    </TableRow>
                    <TableRow android:layout_height="wrap_content"
                        android:layout_width="wrap_content" android:id="@+id/tableRow010">
                    </TableRow>
                </TableLayout>
            </ScrollView>
        </FrameLayout>
    </RelativeLayout>
</RelativeLayout>
</TabHost>

Hope somebody can help me out with this one.
Thanks in advance.

  • 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-25T10:10:55+00:00Added an answer on May 25, 2026 at 10:10 am

    You may need to create a gloabl reference to the textview as it is in the xml layout you specify for the tab activity. But you are trying to access the textview from its child activity(activity used to represent a tab.). When you use findViewById in the child activity it will look into the layout or view that was specified for the activity.

    EDIT: Way to use app context.

    Extend the application class and add a attribute of type textview. So in your activity you can access the application context and set the text view a attribute.

    MyApplication appContext = (MyApplication) getApplicationContext();
    appContext.textview = (TextView) findViewById(R.id.textview1);
    

    In any other activity you can access that text view the same way.

    MyApplication appContext = (MyApplication) getApplicationContext();
    
    This will have the textview appContext.textview
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really sure how to title this question but basically I have an
First of all sorry of asking such a dumb question, I am quite a
I have quite a simple question I think, but I need a definitive answer.
This is going to seem quite a lame question - basically we have downloaded
I think that this is a newbie type question but I have quite understood
I am asking this out of a curiosity. Basically my question is when you
This is more a learning question than coding, but I'm certain it's a common
Quite a simple question, but I haven't been able to find any useful resources
I have quite an specific question about image recognition. I have to write a
This is a very open question about a problem that we have. Basically, we

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.