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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:47:57+00:00 2026-06-09T02:47:57+00:00

eveything looks to be fine, but I still get error when I try to

  • 0

eveything looks to be fine, but I still get error when I try to change the view by pressing the button.
Here is code:

    package com.example.testy;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {

    ViewFlipper flipper;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
        setContentView(R.layout.activity_main);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void clcik(View v) {
        flipper.showNext();
    }

}

And here is my XML:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top" >

    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="click"
            android:text="Button!!" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView!!" />
    </ViewFlipper>

</RelativeLayout>

Anyone knows what can be wrong in this code?
Thank you for answers!

  • 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-09T02:47:58+00:00Added an answer on June 9, 2026 at 2:47 am

    Perhaps you should fix the name of your method to click ?

     public void **clcik**(View v) {
            flipper.showNext();
        }
    

    Due the wrong spell (clcik) in our activity code, you may be getting a Exception because Android can’t find the click method.

    And thanks to @yugidroid’s answer I spot one more error on your code:

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
        setContentView(R.layout.activity_main);
    
    }
    

    You call findViewById before even you have any Views (a call to setContentView) . You will get a NullPointException because of that.

    I would recommend you to make a call to super.onCreate the very first line of your onCreate() method. That is what Google does.

    Regarding setting the click listener on layout or creating a listener and setting on the code. Well, there is not much difference, although the latter is certainly faster as the first uses reflection, what has a higher cost than just calling a method.

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

Sidebar

Related Questions

I want to setup jetty with jetty-blazeds extension. Everything looks fine but when I
So what my code looks like.. Now the problem is that Everything is fine
I'm trying to link to a static library, libcovis.a. Everything looks fine but I
I have a bunch of self-hosted WCF services. Everything's working fine but I'm look
I have recently installed clang_complete plugin for VIM. Everything looks fine except in popup
I wrote some code for the ising model in python (2d). Everything looks seems
I have upgrated to JSF2 but still running with facelet1.1.15. I have these parameters
Spent the good part of this morning working through this, but still…. apologies if
This is probably a shot in the dark but here goes nothing... I have
Everything was working fine in Rails 3.0.14, but after changing gem 'rails', '3.0.14' to

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.