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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:22:02+00:00 2026-06-15T04:22:02+00:00

I am trying to change Visibility of FastForward Button present in MediaController Class using

  • 0

I am trying to change Visibility of FastForward Button present in MediaController Class using concept of Reflection.

Below is my code snippet.

package com.example.reflection;

import java.lang.reflect.Field;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ImageButton;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

public class MainActivity extends Activity {

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Class <? > aClass;

        try {

            MediaController controller = new MediaController(this);

            aClass = Class.forName("android.widget.MediaController");

            Field forwardButton = aClass.getDeclaredField("mFfwdButton");
            forwardButton.setAccessible(true);

 NPE--->>   ImageButton button = (ImageButton) forwardButton.get(controller);

            if (null == button) Toast.makeText(this, "Button is null", Toast.LENGTH_LONG)
                .show();
            else button.setVisibility(View.INVISIBLE);

            videoView = (VideoView) findViewById(R.id.videoView);
            videoView.setVideoPath(Environment.getExternalStorageDirectory() + "/Video/NeYo.flv");
            videoView.setMediaController(controller);
            videoView.requestFocus();

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }
}

I get NullPointerException while fetching ImageButton.

Can somebody please point out the error I am making?

Thanks

Anyways I got the answer for this question.

mFfwdButton is instantiated only when the View is inflated. Thats why I was getting a null. I was trying to get the variable even before MediaController has been attached to VideoView.

I followed following approach and it worked.It may not be best practice in production environment,but below snippet worked for me.

@Override
protected void onResume() {
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            ImageButton button;
            try {
                button = (ImageButton) forwardButton.get(controller);

                if (null == button) Toast.makeText(MainActivity.this, "Button is null",
                Toast.LENGTH_LONG).show();
                else button.setVisibility(View.INVISIBLE);
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }, 50);
    super.onResume();
}
  • 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-15T04:22:03+00:00Added an answer on June 15, 2026 at 4:22 am

    mFfwdButton is instantiated only when the View is inflated. So you are getting a null. So i guess you cannot use it until the activity has been shown to the user. You are trying to get the variable even before mediacontroller has been attached to VideoView

    Try posting a runnable with a delay in OnResume

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

Sidebar

Related Questions

I'm trying to set a button's event to change a grid's visibility using just
I am trying to make a Button change the visibility of a single ImageButton
Am trying to change the button frame according to the orientation change but button
I'm trying to change the visibility of a pair of server controls (specifically a
I'm using KML to load an image overlay, and then I'm trying to change
I'm trying to change visibility of all SIMPLE-only products via SQL. Here is how
I'm trying to change the css property visibility of a div to visible with
I'm trying change an input mask for textbox when the the check box has
I´m trying to change a spring jsp example to use freemarker. I changed all
im trying to change font globally for whole application, the problem is, i am

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.