Forums > Java

mxp crashes when i create a mxj object

May 29, 2009 | 6:03 pm

hey.. whenever i create a mxj object, mxp suddenly shutsdown..

did this happen to any of you? is there a way to fix this bug?


June 2, 2009 | 1:58 pm

This could be a problem with your java installation. Assure that you have the lastest version installed (by Software Update or http://www.java.com/en/download if you are on windows).


June 2, 2009 | 2:18 pm

hey dude,

i’m using mac machine.. here’s the specs

Mac OS X on a Mac Mini machine.
version 10.5.5
Process 1.83 GHz Intel core duo (Memory – 1Gb 67 MHz DDR2 SDRAM)
Java Compiler – Version 1.5.0

I also noticed this error on my windows machine:

Windows XP Service pack 3
Dell Precision PW390
Intel Core2 CPU 6600 at 2.4 GHz (Ram – 1gb)
Java Compiler – version 6 build 13.

I was able to work around by copy pasting a bit of code.. compiling and testing as i copy/pasted. But i have to get this working on the mac machine, and the copy/paste method isn’t an option on the mac machine because it continues to crash.

Thanks for your help!


June 2, 2009 | 2:56 pm

Very strange. Can you run other java programs, from class files of applets?

For instance, try to compile and run this program:

public class Hello {

    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
Quote:
I was able to work around

What do you mean here? Did you successfully create and use an mxj object? Then mxj and your java virtual machine should be OK and the error is probably in your code.


June 2, 2009 | 2:59 pm

Btw, the java version on your mac is out of date. You can download the latest version from here.


June 2, 2009 | 2:59 pm

yeah, when i meant work around..

i was able to copy/paste the code from the crashy mxj object and paste it into the new mxj object as i compiled and tested each section of code..

These are the exact steps i took:

I created the mxj quickie object

I opened the java source, and edited, and compiled it.

I created the mxj object

I repeated this process as i was adding and testing more code… at which point the crash happens. and there’s no going back.. so i end up creating a new mxj quickie object and repeating the process.


June 2, 2009 | 3:01 pm

oh, you’re right about the java version.. i’ll update it and see what happens


June 2, 2009 | 3:21 pm

Oh then I misunderstood you. Its always good to be specific, "whenever i create a mxj" may lead others to think you experience a crash on upon creating any mxj.

Your JVM is probably alright then, though upgrading it does no harm. If you post the code for your java object we might be able to help you further.


June 2, 2009 | 4:27 pm

I attached the entire java program here..

This program is supposed to read the file-name (the file is in the same folder) and print the captions on the screen. The program reads through the entire .srt file and sets up the timings and captions to print, and the function execute() takes care of updating the clock and displaying captions on the screen.

import com.cycling74.max.*;
import java.util.*;
import java.io.*;
import java.util.Date;

public class cd extends MaxObject implements Executable
{

    String filename = "moviesubs.srt";
    MaxClock clock;

	ArrayList allcaps;
	ArrayList starttimes;
	ArrayList endtimes;
	ArrayList delaytimes;
	int capscount = 0;
	boolean state; //true - captions are on the screen; false - no captions are on the screen.

	int height;
	int width;
	int fsize;//fontsize ref

		BufferedReader reader;
		File subs ;
	public void init () throws IOException{
	   subs	= new File (filename);
 	   reader	= new BufferedReader(new FileReader(subs));
		allcaps = new ArrayList();
		starttimes = new ArrayList();
		endtimes = new ArrayList();
		delaytimes = new ArrayList();
		capscount = 0;
		outlet (3, "set", "");
	}

	private static final String[] INLET_ASSIST = new String[]{
		"inlet 1 help"
	};
	private static final String[] OUTLET_ASSIST = new String[]{
		"outlet 1 help"
	};

	public cd(Atom[] args)
	{
		declareInlets(new int[]{DataTypes.ALL, DataTypes.ALL}); //height, width
		declareOutlets(new int[]{DataTypes.ALL, DataTypes.ALL, DataTypes.ALL, DataTypes.ALL, DataTypes.ALL });

		setInletAssist(INLET_ASSIST);
		setOutletAssist(OUTLET_ASSIST);
		createInfoOutlet(false);

		clock = new MaxClock(this); 

        try {
        		init();

        } catch (IOException e) {
            System.err.println(e);
            System.exit(1);
        }

	}

	public void bang()
	{

        try {
        		init();

        } catch (IOException e) {
            System.err.println(e);
            System.exit(1);
        }

		String line = null;

        try {
		line = reader.readLine();
        while (line != null) {
				line = reader.readLine();
		//post (line);
				if ((line != null) && (line.length() > 3)){
					int mcval = line.indexOf("-->");
					if (mcval > 0) {
						//this is where the values are set.
						int stime = getStarttime(line);
						int etime = getEndtime (line); //returns end time
						int duration = etime - stime; //returns how long the clock must delay

						//call a function which returns the string with full caption.
						String caption = getCaption();
						allcaps.add (caption);
						starttimes.add(stime);
						delaytimes.add(duration);
						endtimes.add (etime);

					}
				}
        }
		reader.close();

        } catch (IOException e) {
            System.err.println(e);
            System.exit(1);
        }

	for (int ar = 0; ar < allcaps.size(); ar ++){
		String p = (String) allcaps.get(ar);
		Integer pi = (Integer) starttimes.get(ar);
		Integer pi2 = (Integer) endtimes.get(ar);
		String fin = p + " " + pi + " " + pi2;
		post(fin);
	}

	//Start the clock here!
	Integer pi = (Integer) starttimes.get(capscount);
	outletBang(0);
	clock.delay(pi);

	}

	public int getStarttime(String line){
		String start = "" +  line.charAt(0) + line.charAt(1);
		int shours = Integer.parseInt(start);
		start = "" + line.charAt(3) + line.charAt(4);
		int smin = Integer.parseInt(start);
		start ="" + line.charAt(6) + line.charAt(7);
		int ssec = Integer.parseInt(start);
		start ="" + line.charAt(9) + line.charAt(10) + line.charAt(11);
		int sms = Integer.parseInt(start);
		int stime = (shours * 60 * 60 * 1000) + (smin * 60 * 1000) + (ssec * 1000) + (sms);

		return stime;
	}

	public int getEndtime(String line){

		int offset = line.indexOf("-->") + 4;
		String end = "" +  line.charAt(0+offset) + line.charAt(1+offset);
		int ehours = Integer.parseInt(end);
		end = "" + line.charAt(3+offset) + line.charAt(4+offset);
		int emin = Integer.parseInt(end);
		end ="" + line.charAt(6+offset) + line.charAt(7+offset);
		int esec = Integer.parseInt(end);
		end ="" + line.charAt(9+offset) + line.charAt(10+offset) + line.charAt(11+offset);
		int ems = Integer.parseInt(end);
		int etime = (ehours * 60 * 60 * 1000) + (emin * 60 * 1000) + (esec * 1000) + (ems);

		return etime;
	}

	public String getCaption (){
		String caption = "";
      	 try {
			String line = reader.readLine();
			while (line != null){
				if (line.length() < 5)
					break;
				caption = caption + "n" +  line;
				line = reader.readLine();
			}

   	     } catch (IOException e) {
            System.err.println(e);
            System.exit(1);
   	     }

	    return caption;
	}

	public void inlet(int i)
	{
	}

	public void inlet(float f)
	{
	}

	public void list(Atom[] list)
	{

		Atom a =  list[0];
		height = a.getInt();
		a = list[1];
		width = a.getInt();
		a = list[2];
		fsize= a.getInt();

	}

     public void execute() {

		if (state == false){
			String tp = (String) allcaps.get(capscount);
			String a = "";
			String b = "";
			String c = "";
			String d = "";

   		  	post ("Execute() - State = false");

			outletBang(0);
			outletBang(3);
			outletBang(0);
			int indexof = tp.indexOf("n", 6);
			post ("indexof :" + indexof);
			if (indexof > 0){
				a = tp.substring(1, indexof);
				post (a);

				outlet(1,  70);
				outlet(2,  180);
				outletBang(2);
				outletBang(1);
				outlet(3, "set", a);
				outletBang(3);

			}

			b = tp.substring(indexof + 1);
			int indexof1 = tp.indexOf("n", indexof + 1);
			post ("indexof : " +  indexof + "indexof1 " + indexof1 );
			if (indexof1 > 0){
				b = tp.substring(indexof + 1, indexof1);
				post (b);
				outlet(1,  70);
				outlet(2,  200);
				outletBang(2);
				outletBang(1);
				outlet(3, "set", b);
				outletBang(3);

				c = tp.substring (indexof1 + 1);
				int indexof2 = tp.indexOf("n", indexof1+1);
				post ("indexof2 : " +  indexof2);
				if (indexof2 > 0){
					c = tp.substring (indexof1 + 1, indexof2);
					post (c);
					outlet(1,  70);
					outlet(2,  220);
					outletBang(2);
					outletBang(1);
					outlet(3, "set", c);
					outletBang(3);

					d = tp.substring (indexof2 + 1);
					int indexof3 = tp.indexOf ("n", indexof2 + 1);
					post ("indexof3 : " +  indexof3);

					if (indexof3 > 0){
						d = tp.substring (indexof2 + 1, indexof3);
						post (d);
						outlet(1,  70);
						outlet(2,  240);
						outletBang(2);
						outletBang(1);
						outlet(3, "set", d);
						outletBang(3);
					}
					else{
						post(d);
						outlet(1,  70);
						outlet(2,  240);
						outletBang(2);
						outletBang(1);
						outlet(3, "set", d);
						outletBang(3);
					}
				}
				else{
					post(c);
					outlet(1,  70);
					outlet(2,  220);
					outletBang(2);
					outletBang(1);
					outlet(3, "set", c);
					outletBang(3);
				}
			}
			else {
				post (b);
				outlet(1,  70);
				outlet(2,  200);
				outletBang(2);
				outletBang(1);
				outlet(3, "set", b);
				outletBang(3);

			}

				clock = new MaxClock (this);
				if (capscount < delaytimes.size()){
					Integer pi = (Integer) delaytimes.get(capscount);
					clock.delay(pi);
				}
				state = true;
		}
		else if (state == true){
   		  	post ("Execute() - State = true");
			outletBang(0);
			state = false;
			if (capscount < starttimes.size() - 1){
				clock = new MaxClock (this);
				Integer pi = (Integer) starttimes.get(capscount + 1) - (Integer) endtimes.get(capscount);
				capscount ++;
				clock.delay(pi);
			}
		}
     }

}

June 2, 2009 | 6:30 pm

You’re using outlet in your constructor which is not allowed. You need to defer that call or use the loadbang() method.


November 4, 2009 | 9:52 am

I’m having a similar problem – whenever i try and create a
mxj net.tcp.recv @port (port)
object in a new patch, max crashes

Sad

Am i doing something wrong?

I have downloaded and installed the latest Java Runtime Environment, i’m running XP with Max 5.


Viewing 11 posts - 1 through 11 (of 11 total)