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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:34:20+00:00 2026-06-17T09:34:20+00:00

I’m trying to load a new view when I push a Button. I have

  • 0

I’m trying to load a new view when I push a Button. I have a viewPager and the button is on those views. When I call onClick my app never starts, it crashes before anything happens. I’ve been trying to squash this bug for over a week and I think it’s something very amateur. Please help a student programmer!

public class Main extends Activity {

    Button listButton;

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

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splash);

        SplashPager adapter = new SplashPager();
        ViewPager myPager = (ViewPager) findViewById(R.id.splashPager);
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(0);

        listButtonListener();
    }

    public void listButtonListener() {

        listButton = (Button) findViewById(R.id.splashB);
        listButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                setContentView(R.layout.list_layout);

            }

        });

    }

}

Log:

01-16 20:09:49.149: W/dalvikvm(29035): threadid=1: thread exiting with uncaught exception         (group=0x40207560)
01-16 20:09:49.149: E/AndroidRuntime(29035): FATAL EXCEPTION: main
01-16 20:09:49.149: E/AndroidRuntime(29035): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.survtest2/com.example.survtest2.Main}: java.lang.NullPointerException
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Looper.loop(Looper.java:130)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.main(ActivityThread.java:3733)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invokeNative(Native Method)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invoke(Method.java:507)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:650)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at dalvik.system.NativeStart.main(Native Method)
01-16 20:09:49.149: E/AndroidRuntime(29035): Caused by: java.lang.NullPointerException
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.listButtonListener(Main.java:36)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.onCreate(Main.java:30)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
01-16 20:09:49.149: E/AndroidRuntime(29035):    ... 11 more
01-16 20:09:49.149: E/AndroidRuntime(29035): [Blue Error Handler] Make Debugging Report file for main
01-16 20:09:49.149: E/AndroidRuntime(29035): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.survtest2/com.example.survtest2.Main}: java.lang.NullPointerException
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.os.Looper.loop(Looper.java:130)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.main(ActivityThread.java:3733)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invokeNative(Native Method)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at java.lang.reflect.Method.invoke(Method.java:507)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:650)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at dalvik.system.NativeStart.main(Native Method)
01-16 20:09:49.149: E/AndroidRuntime(29035): Caused by: java.lang.NullPointerException
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.listButtonListener(Main.java:36)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at com.example.survtest2.Main.onCreate(Main.java:30)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-16 20:09:49.149: E/AndroidRuntime(29035):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
01-16 20:09:49.149: E/AndroidRuntime(29035):    ... 11 more

splash.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<android.support.v4.view.ViewPager
    android:id="@+id/splashPager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</android.support.v4.view.ViewPager>

</LinearLayout>

splash2.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/intro__1" />

<Button
    android:id="@+id/splashB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginLeft="75dp"
    android:text="aaaaaaaaaaaaaaaaaa" />

</FrameLayout>

ViewPager:

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 4;
}

@Override
public Object instantiateItem(View collection, int position) {
    LayoutInflater inflater = (LayoutInflater) collection.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int resId = 0;
    switch (position) {

    case 0:
        resId = R.layout.splash2;
        break;
    case 1:
        resId = R.layout.splash3;
        break;
    case 2:
        resId = R.layout.splash4;
        break;
    case 3:
        resId = R.layout.splash5;
        break;

    }

    View view = inflater.inflate(resId, null);
    ((ViewPager) collection).addView(view, 0);
    return view;

}

@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
    // TODO Auto-generated method stub
    ((ViewPager) arg0).removeView((View) arg2);
}

@Override
public Parcelable saveState() {
    // TODO Auto-generated method stub
    return null;
}

@Override
public boolean isViewFromObject(View arg0, Object arg1) {
    // TODO Auto-generated method stub
    return arg0 == ((View) arg1);
}

}
  • 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-17T09:34:21+00:00Added an answer on June 17, 2026 at 9:34 am

    Based on your failure at listButton.setOnClickListener, I’m guessing that R.id.splashB is not being found in your layout.

    public class Main extends Activity {
    
    Button listButton;
    View splash2;  // Added
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        setContentView(R.layout.splash);
        SplashPager adapter = new SplashPager();
        ViewPager myPager = (ViewPager) findViewById(R.id.splashPager);
        ....
        LayoutInflater inflater = getLayoutInflater(); // Added
        splash2 = inflater.inflate (R.layout.splash2, null); // Added
        myPager.add (splash2); // Added
    
        listButtonListener();
    }
    
    public void listButtonListener() {
    
        listButton = (Button) splash2.findViewById(R.id.splashB); // Changed
        listButton.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View arg0) {
                setContentView(R.layout.list_layout);
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.