Could not find a TextView by calling findViewById method

This is a discussion on Could not find a TextView by calling findViewById method within the Beginning Developers forums, part of the Android Development category; Hello, I cannot find a TextView by calling findViewById method even through the ID does exists. please see my code: Activity: public class OtherActivity extends ...

Results 1 to 3 of 3

Thread: Could not find a TextView by calling findViewById method

  1. #1
    Android Lurker zhangzhexin_81's Avatar
    Join Date
    Jul 2011
    Posts
    4
    Thanked
    1 times

    Post Could not find a TextView by calling findViewById method

    Hello, I cannot find a TextView by calling findViewById method even through the ID does exists.
    please see my code:
    Activity:
    public class OtherActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
    TextView textView = (TextView)findViewById(R.ID.txt02);
    super.onCreate(savedInstanceState); // line 5
    setContentView(R.layout.other_activity);
    ...
    }
    ...
    }
    I add a breakpoint at line5 and start project in debug mode, when the executing stopped at the break point, I moved the mouse to variable textView, it is null.
    You can see my other_activity.xml under layout folder like below:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    androidrientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
    android:id="@+ID/txt02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />

    </LinearLayout>

    and the content in R.java like below:
    public final class R {
    public static final class ID {
    public static final int Activity01_btn=0x7f050001;
    public static final int otherActivity_Btn=0x7f050003;
    public static final int txt01=0x7f050000;
    public static final int txt02=0x7f050002;
    }

    public static final class attr {
    }
    public static final class drawable {
    public static final int icon=0x7f020000;
    }
    public static final class layout {
    public static final int main=0x7f030000;
    public static final int other_activity=0x7f030001;
    }Activity01.zip
    public static final class string {
    public static final int app_name=0x7f040001;
    public static final int hello=0x7f040000;
    public static final int other=0x7f040002;
    public static final int otherActivityBtn=0x7f040003;
    }
    }

    So, I don't think the TextView could not be found, but why the variable textView is null. I was confused.
    could you please help me ?
    Additional, the attached is my source files.

  2. Android.net is the premier Android Forum. Registered users do not see these ads. .

  3. #2
    App Developer alostpacket's Avatar
    Join Date
    Jan 2011
    Location
    NY
    Posts
    240
    Thanked
    32 times
    Twitter
    alostpacket
    you have to call setContentView(layoutID); first

  4. #3
    Android Lurker zhangzhexin_81's Avatar
    Join Date
    Jul 2011
    Posts
    4
    Thanked
    1 times
    Thanks very much!

Remove Ads

http://www.scramblerducati.org/

Sponsored Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Similar Threads

  1. One Click Root Method for Optimus V. Gingerbreak 1.2
    By vegetajin8 in forum LG Optimus V
    Replies: 27
    Last Post: 10-12-2012, 06:58 PM
  2. How to Draw TextView on Canvas in android..?
    By Rajesh Kalhotra in forum Beginning Developers
    Replies: 3
    Last Post: 03-09-2011, 03:41 PM
  3. How to Draw TextView on Canvas in android..?
    By Rajesh Kalhotra in forum Android Forum
    Replies: 2
    Last Post: 03-09-2011, 03:55 AM
  4. A Simple Method of Burning Files to PS3
    By Epic Forums User in forum Samsung Epic 4G
    Replies: 0
    Last Post: 12-23-2010, 01:32 AM

Search tags for this page

android find textview
,
android find textview by id
,
android find view by id
,

android findviewbyid

,
android findviewbyid not found
,
android findviewbyid textview
,
android get textview by id
,
android textview findviewbyid
,

findviewbyid

,

findviewbyid android

,
findviewbyid not working
,
findviewbyid textview
,
textview android findviewbyid
,
textview find by id
,
textview findviewbyid
Click on a term to search our sites for related topics.
Android Forum