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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:50:41+00:00 2026-05-22T15:50:41+00:00

I am doing code for calculating bpm for media files. my requirement is i

  • 0

I am doing code for calculating bpm for media files. my requirement is i have to play song only for 5 seconds not more than 5 seconds. so i use Thread.sleep(5000) and i call handler message. it throws java.long.stackoverflowexception.

my code:

currentThread.start(); 
....    
    public void run() {
        try {
            Log.e("bpm", "in run method");
            BPM2SampleProcessor processor = new BPM2SampleProcessor();
            processor.setSampleSize(1024);
            EnergyOutputAudioDevice output = new EnergyOutputAudioDevice(processor);     
            output.setAverageLength(1024);      
            try {
                player = new Player(new FileInputStream("/sdcard/taxi.mp3"), output); // line no 40
                currentThread.run();  // line no 41
                player.play();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (JavaLayerException e) {
                e.printStackTrace();
            }
           text.setText("bpm is  "+processor.getBPM());
           Log.e("bpm","  bpm is  "+processor.getBPM());            
           Thread.sleep(5000);
       threadHandler.sendEmptyMessage(0);
                         Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }       
    }

private Handler threadHandler = new Handler() 
{
    public void handleMessage(android.os.Message msg) 
    {
     Log.e("calledThread","5seconds");  
     player.close();
    }
};  

log cat:

  05-20 18:05:01.761: ERROR/AndroidRuntime(2777): Uncaught handler: thread Thread-8 exiting due to uncaught exception
  05-20 18:05:02.237: ERROR/AndroidRuntime(2777): java.lang.StackOverflowError
  05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:49)
  05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:45)
  05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.ReadWriteHeapByteBuffer.<init>(ReadWriteHeapByteBuffer.java:49)
  05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.BufferFactory.newByteBuffer(BufferFactory.java:51)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.ByteBuffer.allocate(ByteBuffer.java:54)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:351)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.nio.charset.Charset.encode(Charset.java:711)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.lang.String.getBytes(String.java:1022)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at org.apache.harmony.luni.util.Util.getBytes(Util.java:61)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.io.File.properPath(File.java:1362)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.io.FileInputStream.<init>(FileInputStream.java:77)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.io.FileInputStream.<init>(FileInputStream.java:130)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at beatit.beatit.main2.run(main2.java:40)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.lang.Thread.run(Thread.java:1096)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at  beatit.beatit.main2.run(main2.java:41)
 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.lang.Thread.run(Thread.java:1096)

 05-20 18:05:02.237: ERROR/AndroidRuntime(2777):     at java.la
 05-20 18:05:05.573: ERROR/JavaBinder(1276): !!! FAILED BINDER TRANSACTION !!!
  • 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-22T15:50:41+00:00Added an answer on May 22, 2026 at 3:50 pm

    You almost answered yourself:

    currentThread.run();  // line no 41
    

    Below I wrote example how to deal with your problem:

        AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                //put your code here
            }
        };
    
        try {
            task.execute((Void)null).get(5, TimeUnit.SECONDS);
        } catch(Exception e) {
            e.printStackTrace();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code doing this : var changes = document.getElementsByName(from); for (var c=0;
I have the following PHP code doing a very simple select into a table.
I have C code doing some calculations (irrelevant to my question, I believe ).
I've been doing code review (mostly using tools like FindBugs) of one of our
I'm doing code review and came across a class that uses all static methods.
I am currently doing a code review and the following code made me jump.
What are the benefits of doing static code analysis on your source code? I
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both
In C# 3.0, I'm doing the code below to declare a DateTime property and
I'm doing some ASM code in a C code with the asm function. My

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.