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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:50:44+00:00 2026-06-14T13:50:44+00:00

I am trying to display a youtube video in full screen mode using VideoView.

  • 0

I am trying to display a youtube video in full screen mode using VideoView. I have written small piece of code before implementing it but I am getting nullPointerException. Below is my sample code I wrote.

I made entry in AndroidManifest.xml file for permissions..

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I have created a videoview layout in main.xml

<VideoView 
  android:id="@+id/VideoView"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent" />

My source file looks like this..

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
VideoView vv = (VideoView) findViewById(R.id.VideoView);                        
MediaController mc=new MediaController(this);
mc.setEnabled(true);
vv.setVideoURI(Uri.parse("http://www.youtube.com/v/Iq81rUGQofk"));
vv.setMediaController(mc);
vv.requestFocus();
vv.showContextMenu();
vv.start(); 
setContentView(R.layout.main);
}

This is throwing, below exception.

11-19 03:11:50.558: E/AndroidRuntime(11488): FATAL EXCEPTION: main
11-19 03:11:50.558: E/AndroidRuntime(11488): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mydemoapp/com.example.mydemoapp.MainActivity}: java.lang.NullPointerException
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1999)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2024)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.ActivityThread.access$600(ActivityThread.java:126)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.os.Looper.loop(Looper.java:137)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.ActivityThread.main(ActivityThread.java:4479)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at java.lang.reflect.Method.invokeNative(Native Method)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at java.lang.reflect.Method.invoke(Method.java:511)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at dalvik.system.NativeStart.main(Native  Method)
11-19 03:11:50.558: E/AndroidRuntime(11488): Caused by: java.lang.NullPointerException
11-19 03:11:50.558: E/AndroidRuntime(11488):    at com.example.mydemoapp.MainActivity.onCreate(MainActivity.java:30)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.Activity.performCreate(Activity.java:4628)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-19 03:11:50.558: E/AndroidRuntime(11488):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1963)

Please let me know if my approach to this is not correct.

  • 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-14T13:50:45+00:00Added an answer on June 14, 2026 at 1:50 pm

    move the setContentView(R.layout.main); after the call to super.onCreate(). Like following

    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    
    setContentView(R.layout.main);
    
    VideoView vv = (VideoView) findViewById(R.id.VideoView);                        
    MediaController mc=new MediaController(this);
    mc.setEnabled(true);
    vv.setVideoURI(Uri.parse("http://www.youtube.com/v/Iq81rUGQofk"));
    vv.setMediaController(mc);
    vv.requestFocus();
    vv.showContextMenu();
    vv.start(); 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m trying to display a page of embed YouTube videos. I got the code
I'm trying to play a video via RTSP using Adobe Air, I have the
trying to display data only after variables have been set. $(document).ready(function () { function
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm trying to get the views of a video in Youtube through YQL to
I'm trying to embed a youtube video on my site and it doesn't seem
I am trying to display images vertically 5 per row using php and I
I am new to JQuery and am trying to display a YouTube playlist in
I'm breaking my head over this. I'm trying to insert embeddable video code, such
Im trying to display a simple immediate mode sets of textured polygons with pyOpenGL

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.