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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:35:16+00:00 2026-05-28T20:35:16+00:00

I’m working on an Android project using API 7 and I’m trying to start

  • 0

I’m working on an Android project using API 7 and I’m trying to start a ViewPager, but the app keeps crashing whenever I try to create the activity that uses the ViewPager from the main activity. I’ve checked all my resources and they’re in their proper directories, but I’m stumped.

Here’s the activity that attempts to start the ViewPager:

public class World extends Activity{

    MediaPlayer muzak;
    Boolean mSwitch;

    final Preferencer pp = (Preferencer)getApplicationContext();

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        ViewPagerAdapter adapter = new ViewPagerAdapter();
        ViewPager myPager = (ViewPager) findViewById(R.id.viewpager);
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(1);


        if(pp.getMuzak()){
            muzak = MediaPlayer.create(World.this, R.raw.level1);
            muzak.setLooping(true);
            muzak.start();
        }

        Button zoom = (Button) findViewById(R.id.subbutton);
        zoom.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), Subworld.class);
                startActivityForResult(myIntent, 0);
            }

        });

    }

    @Override
    protected void onPause(){
        super.onPause();
        if(pp.getMuzak()){
        muzak.release();
        }
    }
}

And the main activity that starts this activity is as follows:

public class MainActivity extends Activity {

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

        Button next = (Button) findViewById(R.id.button1);
        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                 Intent myIntent = new Intent(view.getContext(), World.class);
                 startActivityForResult(myIntent, 0);
            }
        });

        final ImageButton tog = (ImageButton) findViewById(R.id.button2);
        tog.setTag(2);
        tog.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                final int status = (Integer) view.getTag();

                if (status == 1){
                    tog.setImageResource(R.drawable.ic_lock_silent_mode_off);
                    view.setTag(2);
                }
                else if (status == 2){
                    tog.setImageResource(R.drawable.ic_lock_silent_mode);
                    view.setTag(1);
                }
            }

        });
    }
}

When I tried pasting the same exact code to initialize the ViewPager into the main activity, it works just fine, but I would much prefer to start the ViewPager in a separate activity so that when the user hits the hard back button, it will go back to the main activity. But I suppose putting that snippet of code back into the main activity would be okay, it’s just my only problem is that the ViewPager contains layouts that are supposed to have buttons that also start new activites in them. So if there’s a work around that too, that would be good to know.

I also know that the custom class “preferencer” that I call in both activities works, so I doubt that’s the problem.

I’ve searched the internet for a few days now and I am really clueless at this point. Sorry about the massive amounts of text and terrible formatting, I’m a newb here, so pardon my newbness. Any insight on this would be very greatly appreciated. Thanks!

Edit:

Here is the logcat stack trace:

01-30 12:23:00.958: D/dalvikvm(227): GC freed 711 objects / 55944 bytes in 158ms
01-30 12:23:12.808: D/AndroidRuntime(227): Shutting down VM
01-30 12:23:12.818: W/dalvikvm(227): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-30 12:23:12.818: E/AndroidRuntime(227): Uncaught handler: thread main exiting due to uncaught exception
01-30 12:23:12.848: E/AndroidRuntime(227): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.Hey.namespace/com.Hey.namespace.World}: java.lang.NullPointerException
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.os.Looper.loop(Looper.java:123)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.ActivityThread.main(ActivityThread.java:4363)
01-30 12:23:12.848: E/AndroidRuntime(227):  at java.lang.reflect.Method.invokeNative(Native Method)
01-30 12:23:12.848: E/AndroidRuntime(227):  at java.lang.reflect.Method.invoke(Method.java:521)
01-30 12:23:12.848: E/AndroidRuntime(227):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-30 12:23:12.848: E/AndroidRuntime(227):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-30 12:23:12.848: E/AndroidRuntime(227):  at dalvik.system.NativeStart.main(Native Method)
01-30 12:23:12.848: E/AndroidRuntime(227): Caused by: java.lang.NullPointerException
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
01-30 12:23:12.848: E/AndroidRuntime(227):  at com.Hey.namespace.World.<init>(World.java:16)
01-30 12:23:12.848: E/AndroidRuntime(227):  at java.lang.Class.newInstanceImpl(Native Method)
01-30 12:23:12.848: E/AndroidRuntime(227):  at java.lang.Class.newInstance(Class.java:1479)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-30 12:23:12.848: E/AndroidRuntime(227):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
01-30 12:23:12.848: E/AndroidRuntime(227):  ... 11 more
01-30 12:23:12.888: I/dalvikvm(227): threadid=7: reacting to signal 3
01-30 12:23:12.929: I/dalvikvm(227): Wrote stack trace to '/data/anr/traces.txt'
  • 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-28T20:35:17+00:00Added an answer on May 28, 2026 at 8:35 pm

    You are using findViewById inside onCreate of your World Activity, but you did not call setContentView before it.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
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
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.