Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new for mat-lab and java , so i would like to list add in while loop .below i have mentioned ?

OS: Windows 7 ,64 bit .

  • On Mat-lab Part Side

list=java.util.ArrayList();
for k=1:length(matrix)
list.add(int32(matrix(k)));
end
import edu.lipreading.*;
training = MainMethod;
training.list_method(list);

  1. on Java Class Part Side

    public void list_method(List<Integer> points){
    
       while(true){
    
         Sample sample = new Sample();
    
         sample.getMatrix().add(points);}
    
     }
    

When I am run my mat-lab i got Error :

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2734)
    at java.util.Vector.ensureCapacityHelper(Vector.java:226)
    at java.util.Vector.add(Vector.java:728)
    at edu.lipreading.MainMethod.onRecord(MainMethod.java:40)
    at edu.lipreading.MainMethod.list_method(MainMethod.java:26)

Note : I have referred link also : java.lang.OutOfMemoryError: Java heap space on startup

share|improve this question
    
Why is the while loop infinite? –  vandale Mar 11 at 2:53
    
thanks for reply me . because i am list add i expected result like sample.getMatrix().add(points); //My List values are like [1,2,3,4,5,6,7,8][9,8,3,2,2,43,22,1] [33,2,2,2,23,2,2,2] etc –  user3391749 Mar 11 at 3:12

2 Answers 2

you do not need infinite while loop, for your case this will work assuming getMatrix returns a list object and you are adding another list to it.

     Sample sample = new Sample();

     sample.getMatrix().add(points);

if you want to add only the contents of list to getMatrix() list then you can do:

     sample.getMatrix().addAll(points);

Hope this helps.

share|improve this answer
    
Thanks for reply me , i have tried Collection public void list_method(Collection<? extends List<Integer>> points){sample.getMatrix().addAll(points);} I have got result output like :Sample [id=web cam 10:41:06 11/03/2014, matrix=[136, 41, 1, 41, 77, 8, 77, 72]] ;Sample [id=web cam 10:41:12 11/03/2014, matrix=[170, 49, 10, 49, 88, 10, 88, 84]] etc..I have expected to get result like Sample [id=web cam 10:41:12 11/03/2014, matrix=[136,41,1,41,77,8,77,72],[170, 49, 10, 49, 88, 10, 88, 84]] –  user3391749 Mar 11 at 5:15
    
Can you please show your calling code and Sample Class code –  Sanjeev Mar 11 at 6:14
    
Once again thanks for reply me. My Calling Code On Mat-lab side part from input web cam video processing i got 1-by-8 matrix co-ordinates values while(1) matrix = [right_lip_x;right_lip_y;left_lip_xy;left_lip_yx;upper_lip_x;upper_lip_y;bottom_‌​lip_x;bottom_lip_y]; %from rest of code available in this same forum end on Java Code Part Sample Class having private List<List<Integer>> matrix;//Getter Setter public List<List<Integer>> getMatrix() { return matrix;} –  user3391749 Mar 11 at 6:23
    
In that case the first one will work sample.getMatrix().add(points) and the sample object must be created only once. –  Sanjeev Mar 11 at 10:22
    
Thanks for reply me . please let me know brief description with example ? –  user3391749 Mar 12 at 0:16

If you're running out of Java heap space in MATLAB, you can increase the amount of memory assigned to it in the MATLAB preferences.

Depending on your version of MATLAB, open the preferences dialog either by selecting Preferences from the File menu, or clicking Preferences in the toolstrip.

Under the section General, Java Heap Memory, you should find a setting that controls the Java heap size. The default is pretty low, so increase it to whatever you feel is necessary. You'll need to restart MATLAB to have that setting take effect.

share|improve this answer
    
Thanks for reply me .i have increased java heap size maximum up to 1433 MB set after i have closed my mat-lab then again i have run my mat-lab application again i got same error ? –  user3391749 Mar 12 at 0:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.