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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:14:04+00:00 2026-05-27T16:14:04+00:00

I am trying to record a video on my android project. I have found

  • 0

I am trying to record a video on my android project.

I have found some exemples on the internet but nothing is working.
Normaly, i have to use the MediaRecorder

Can you give me a simple exemple, i don’t need to visualise the video when is token, only to register it on my sdcard, that’s all.

Here is an exemple of what I am trying to do:

public class VideoCapture extends Activity {  

    MediaRecorder recorder;  
    Button buttonStart = (Button)findViewById(R.id.buttonstart);  
    Button buttonStop = (Button)findViewById(R.id.buttonstop);  

    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        recorder = new MediaRecorder();  
        initRecorder();  
    }  

    private void initRecorder() {  
        recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);  
        recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);  
        recorder.setProfile(cpHigh);  
        recorder.setOutputFile("/sdcard/videocapture_example.mp4");  
        recorder.setMaxDuration(50000);  
        recorder.setMaxFileSize(5000000);  
    }  

    private void prepareRecorder() {  
        try {  
            recorder.prepare();  
        } catch (IllegalStateException e) {  
            e.printStackTrace();  
            finish();  
        } catch (IOException e) {  
            e.printStackTrace();  
            finish();  
        }  
    }  

    buttonStart.setOnClickListener(new Button.OnClickListener()

            {  
        @Override  
        public void onClick(View v)  
        {  
        initRecorder();  
            prepareRecorder();  
        }});  

    buttonStop.setOnClickListener(new Button.OnClickListener(){  
        @Override  
        public void onClick(View v)  
        {  
            recorder.stop();  
        }
    }); 
}

Stacktrace:

12-25 22:04:24.188: E/AndroidRuntime(1361): FATAL EXCEPTION: main
12-25 22:04:24.188: E/AndroidRuntime(1361): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{test.milos.net/test.milos.net.TestVideoNetActivity}: java.lang.ClassNotFoundException: test.milos.net.TestVideoNetActivity in loader dalvik.system.PathClassLoader[/data/app/test.milos.net-2.apk]
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.os.Looper.loop(Looper.java:126)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.ActivityThread.main(ActivityThread.java:3997)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at java.lang.reflect.Method.invokeNative(Native Method)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at java.lang.reflect.Method.invoke(Method.java:491)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at dalvik.system.NativeStart.main(Native Method)
12-25 22:04:24.188: E/AndroidRuntime(1361): Caused by: java.lang.ClassNotFoundException: test.milos.net.TestVideoNetActivity in loader dalvik.system.PathClassLoader[/data/app/test.milos.net-2.apk]
12-25 22:04:24.188: E/AndroidRuntime(1361):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
12-25 22:04:24.188: E/AndroidRuntime(1361):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
12-25 22:04:24.188: E/AndroidRuntime(1361):     ... 11 more
  • 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-27T16:14:05+00:00Added an answer on May 27, 2026 at 4:14 pm

    As guessed, you do a few things wrong that don’t have anything to do with the actual video recording.

    First problem:

    Button buttonStart = (Button)findViewById(R.id.buttonstart);  
    Button buttonStop = (Button)findViewById(R.id.buttonstop);  
    

    You can’t call findViewById() here. findViewById() only searches in the activities current view hierachy. At the point where your class gets instatiated, there is no view hierachy present. These class members will always be null, because that is what gets returned if the view cannot be found. You can keep the variable declaration, but move the search part into onCreate(), after you call setContentView(), for example like this:

    setContentView(R.layout.main);
    buttonStart = (Button)findViewById(R.id.buttonstart);  
    buttonStop = (Button)findViewById(R.id.buttonstop); 
    

    Same goes for your two setOnClickListener() calls on the bottom. They have to be inside a method. I’d suggest moving these two blocks into onCreate() as well, after the findViewById() calls.


    Edit: The stacktrace indicates that your app tries to run an activity named TestVideoNetActivity. Your actual activity is named VideoCapture.

    Open your AndroidManifest and look for a part that looks like this:

        <activity
            android:name=".TestVideoNetActivity"
            ... >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    

    Change TestVideoNetActivity to VideoCapture. Also make sure that your packages match,
    there should be a line package="X" at the top of your manifest and a line package X; at the top of your java source file. Make sure these have the same value for X.


    Edit 2: Your second stacktrace indicates that setAudioSource() failed. All I can think of is that you don’t have the correct permissions set to access the microphone. Add the following lines to your android-manifest (this includes the camera permission too, since you need that as well):

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

    Add them inside the <manifest> tag, but outside of the <application> tag. E.g. after the <uses-sdk> line, if you got one (is included by default I believe).

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

Sidebar

Related Questions

I'm trying to use android.media.MediaRecorder to record video, and no matter what I do
I'm trying to record video with camera in android, but any output format i
Trying to use gem delayed_job from collectiveidea(https://github.com/collectiveidea/delayed_job) in my project, but it throws exception:
Im trying to record video using AVFoundation I can save images but not video.
I am trying to record the voice in android But it will create the
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I am trying to insert a record into a table using Linq but get
I'm trying to associate a video file to a record with a bunch of
I'm trying to use gstreamer 0.10 from Python to simultaneously display a v4l2 video
iam trying to record sound from an activex WMP control playing an internet radio

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.