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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:19:37+00:00 2026-05-29T23:19:37+00:00

I’m using a ViewPager in my project, and having a little problem at setting

  • 0

I’m using a ViewPager in my project, and having a little problem at setting different data on the same layout. So I need to use a setText on my textViews to customize each page.
But I can’t setText() in TextView after inflating ViewGroup that includes that TextView.
Here’s the code:

public class ScheduleActivity extends Activity {

    private List<View> mPages;
    private ViewPager mPager;
    private TitlePageIndicator mTitleIndicator;
    private ArrayList<String> titles;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pages);
        initUi();
    }

    private void initUi() {
        LayoutInflater inflater = LayoutInflater.from(this);
        mPages = new ArrayList<View>();
        titles = new ArrayList<String>();

        titles.add(getString(R.string.monday));
        titles.add(getString(R.string.tuesday));
        titles.add(getString(R.string.wednesday));
        titles.add(getString(R.string.thursday));
        titles.add(getString(R.string.friday));
        titles.add(getString(R.string.saturday));

        for (String title : titles) {

            TextView[] text = new TextView[7];
            text[0] = (TextView) findViewById(R.id.text1);
            text[1] = (TextView) findViewById(R.id.text2);
            text[2] = (TextView) findViewById(R.id.text3);
            text[3] = (TextView) findViewById(R.id.text4);
            text[4] = (TextView) findViewById(R.id.text5);
            text[5] = (TextView) findViewById(R.id.text6);
            text[6] = (TextView) findViewById(R.id.text7);

            for (int i = 0; i < 7; i++) {
                text[i].setText(R.string.monday);
            }

            View day = inflater.inflate(R.layout.schedule, null);

            day.setTag(title);
            mPages.add(day);
        }

        MainPageAdapter adapter = new MainPageAdapter(mPages);
        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(adapter);
        mPager.setCurrentItem(0);

        mTitleIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
        mTitleIndicator.setViewPager(mPager);
        mTitleIndicator.setCurrentItem(0);
        final float density = getResources().getDisplayMetrics().density;
        mTitleIndicator.setTextSize(15 * density); // 15dp
        mTitleIndicator.setFooterLineHeight(1 * density); // 1dp
        mTitleIndicator.setFooterIndicatorHeight(3 * density); // 3dp
        mTitleIndicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
        mTitleIndicator.setFooterColor(0x34B4E3);
        mTitleIndicator.setTextColor(0xAA000000);
        mTitleIndicator.setSelectedColor(0xFF000000);
        mTitleIndicator.setSelectedBold(true);
    }
}

Everything works just great if I remove the setText() line. Here’s the LogCat:

02-15 18:17:54.294: D/AndroidRuntime(465): Shutting down VM
02-15 18:17:54.323: W/dalvikvm(465): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-15 18:17:54.353: E/AndroidRuntime(465): FATAL EXCEPTION: main
02-15 18:17:54.353: E/AndroidRuntime(465): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.stiggpwnz.schedule/com.android.stiggpwnz.schedule.ScheduleActivity}: java.lang.NullPointerException
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.os.Looper.loop(Looper.java:123)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-15 18:17:54.353: E/AndroidRuntime(465):  at java.lang.reflect.Method.invokeNative(Native Method)
02-15 18:17:54.353: E/AndroidRuntime(465):  at java.lang.reflect.Method.invoke(Method.java:521)
02-15 18:17:54.353: E/AndroidRuntime(465):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-15 18:17:54.353: E/AndroidRuntime(465):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-15 18:17:54.353: E/AndroidRuntime(465):  at dalvik.system.NativeStart.main(Native Method)
02-15 18:17:54.353: E/AndroidRuntime(465): Caused by: java.lang.NullPointerException
02-15 18:17:54.353: E/AndroidRuntime(465):  at com.android.stiggpwnz.schedule.ScheduleActivity.initUi(ScheduleActivity.java:63)
02-15 18:17:54.353: E/AndroidRuntime(465):  at com.android.stiggpwnz.schedule.ScheduleActivity.onCreate(ScheduleActivity.java:36)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-15 18:17:54.353: E/AndroidRuntime(465):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-15 18:17:54.353: E/AndroidRuntime(465):  ... 11 more

Line 63 is setText() line.

UPD: changed it to look like this, but still the same exception:

    day = inflater.inflate(R.layout.schedule, null);
    day.findViewById(R.layout.schedule);

    for (String title : titles) {

        TextView[] text = new TextView[7];
        text[0] = (TextView) findViewById(R.id.text1);
        text[1] = (TextView) findViewById(R.id.text2);
        text[2] = (TextView) findViewById(R.id.text3);
        text[3] = (TextView) findViewById(R.id.text4);
        text[4] = (TextView) findViewById(R.id.text5);
        text[5] = (TextView) findViewById(R.id.text6);
        text[6] = (TextView) findViewById(R.id.text7);

        for (int i = 0; i < 7; i++) {
            text[i].setText(R.string.monday);
        }

        day.setTag(title);
        mPages.add(day);
    }

UPD 2: this is how it started to work:

View day = inflater.inflate(R.layout.schedule, null); TextView tv = (TextView)day.findViewById(R.id.text1);
  • 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-29T23:19:38+00:00Added an answer on May 29, 2026 at 11:19 pm

    the problem is here:

    private void initUi() {
        LayoutInflater inflater = LayoutInflater.from(this);
    

    You haven’t yet inflated the layout, and therefore when you write

    text[0] = (TextView) findViewById(R.id.text1);
    

    findview will return null, because there are no views to search for!

    you must first inflate the layout and only AFTER you can programmatically change its content.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.