Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction not getting arguments
    text
    copied!<p>Maybe a silly question, but it's driving me mad.</p> <p>I have a function (<code>readAudioDataFromFile</code>) that's not reciveing it's arguments when called from main. It doesn't throws any compiling error, exceptions or the like, it just returns wrong values.</p> <p>Here some simplified code:</p> <p><code>Main</code> Class</p> <pre><code>package audioCheck; import java.io.FileNotFoundException; public class AudioCheck { public static void main(String[] args) throws FileNotFoundException { String filePath1 = "C:/file1.wav"; String filePath2 = "C:/file2.wav"; new readAudioDataFromFile(filePath1, filePath2); } } </code></pre> <p><code>ReadAudioDataFromFile</code> Class</p> <pre><code>package audioCheck; import java.io.*; public class readAudioDataFromFile { public readAudioDataFromFile(String filePath1, String filePath2) throws FileNotFoundException { // This is the part I hardcode for getting the correct results, instead of passing them as args. // String filePath2 = "C:/file2.wav"; // String filePath1 = "C:/file1.wav"; FileInputStream ins2 = null; FileInputStream ins1 = null; File file2 = new File(filePath2); File file1 = new File(filePath2); int size2 = (int) file2.length(); int size1 = (int) file1.length(); byte [] buffer2=new byte [size2]; byte [] buffer1=new byte [size1]; try { ins2= new FileInputStream(filePath2); ins1= new FileInputStream(filePath1); } catch (FileNotFoundException e) { e.printStackTrace(); } try { //contar e imprimir buffer 2 ins2.read(buffer2, 0,size2); int count2 =0; for(int i=0; i&lt;buffer2.length; i++) { if(buffer2[i]!=0) count2++; } String data2 = String.valueOf((count2)); System.out.println(data2); //contar e imprimir buffer1 ins1.read(buffer1, 0,size1); int count1 =0; for(int i=0; i&lt;buffer1.length; i++) { if(buffer1[i]!=0) count1++; } String data1 = String.valueOf((count1)); System.out.println(data1); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>The thing is that when I hardcode the file paths on <code>readAudioDataFromFile</code>, it works perfectly. Here are the outputs for each case.</p> <p>Tryign to pass args from <code>main</code>:</p> <pre><code>348 388 </code></pre> <p>Hardcoding <code>readAudioDataFromFile</code>:</p> <pre><code>1205739 1346847 </code></pre> <p>Thank you in advice</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload