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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:45:55+00:00 2026-05-28T06:45:55+00:00

I have an Nullpointer Exception with this code, it worked clearly before. Exception shows

  • 0

I have an Nullpointer Exception with this code, it worked clearly before. Exception shows at mainLayout.setOnTouchListener(this), but i don’t understund why. A changed some code in another activity.:

public class Assistantbuilder extends Activity implements OnTouchListener
{
    private ViewFlipper flipper = null;
    private float fromPosition;

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

        LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
        mainLayout.setOnTouchListener(this);

        flipper = (ViewFlipper) findViewById(R.id.flipper);

        LayoutInflater inflater = (LayoutInflater)         getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        int layouts[] = new int[]{ R.layout.dashboard_layout, R.layout.dashboard_layout2, R.layout.dashboard_layout3, R.layout.dashboard_layout4 };
        for (int layout : layouts)
            flipper.addView(inflater.inflate(layout, null));

        Button btndimensions_rafters = (Button) findViewById(R.id.home_btn_dimensions_rafters);
        btndimensions_rafters.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                switch (arg0.getId()) {
                case R.id.home_btn_dimensions_rafters:
                    Intent i = new Intent(Assistantbuilder.this,
                            dimensions_rafters.class);
                    startActivity(i);
                    break;
                }
            }
        });
        Button btngable_roof = (Button) findViewById(R.id.home_btn_gable_roof);
        btngable_roof.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                switch (arg0.getId()) {
                case R.id.home_btn_gable_roof:
                    Intent i = new Intent(Assistantbuilder.this,
                            GableRoof.class);
                    startActivity(i);
                    break;
                }
            }
        });

    }

May be here some mistake:

    public boolean onTouch(View view, MotionEvent event)
    {
        switch (event.getAction())
        {
        case MotionEvent.ACTION_DOWN:
            fromPosition = event.getX();
            break;
        case MotionEvent.ACTION_UP:
            float toPosition = event.getX();
            if (fromPosition > toPosition)
            {
                flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.go_next_in));
                flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.go_next_out));
                flipper.showNext();
            }
            else if (fromPosition < toPosition)
            {
                flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.go_prev_in));
                flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.go_prev_out));
                flipper.showPrevious();
            }
        default:
            break;
        }
        return true;
    }
}

Thanks a lot.

  • 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-28T06:45:55+00:00Added an answer on May 28, 2026 at 6:45 am

    Well, given that line is in the onCreate of your activity, this should always be valid, so the only other thing which could be null is mainLayout. Did you change your XML layout file? The runtime can’t find the LinearLayout with id main_layout.

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

Sidebar

Related Questions

This code is causing a null pointer exception. I have no idea why: private
why SqlLite query in android produce Nullpointer exception I am using this code public
my app crashes with a null pointer exception on the code below. i have
I have a method that looks like this: try { doStuff(); } catch (Exception
I have this code for an expandable list, I want to have a checkbox
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you managed to get Aptana Studio debugging to work? I tried following this,
OK so I have this applet I am making and I want it to
I have the following code: public void someMethod() { Set<Foo> fooSet = bar.getFoos(); for(Foo
Let's say I have an mock object, and I don't want to stub any

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.