We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Fedora Linux and Mac OS X - Java...
Page Index Toggle Pages: 1
Fedora Linux and Mac OS X - Java... (Read 3114 times)
Fedora Linux and Mac OS X - Java...
Jun 22nd, 2009, 12:13pm
 
Does anyone know of differences between Java versions running between these two OSs?

I have developed a Processing app on Fedora (see previous posts about my problems), which I have working on my Fedora machine and have uploaded to a test webserver (I think it is Windows) and all is fine: http://bikefacts.co.uk/Processing/test/house/index.html

However, the exact same code does not run on my Mac OS X 10.5.7? It has Java 1.5 installed.

My Fedora machine is Java version 1.6.0 Build 09. The exact same code, and directory structure, works under Fedora but not on my Mac.

Can anyone advise, is it the versions of Java?
Re: Fedora Linux and Mac OS X - Java...
Reply #1 - Jun 23rd, 2009, 9:04am
 
hmmm,

i just tried the link above on my mac (intel, os 10.5.7, java1.5, safari4) and it works quite well. have you tried to start the javaconsole and see if any exceptions are thrown on your mac?
Re: Fedora Linux and Mac OS X - Java...
Reply #2 - Jun 25th, 2009, 4:50am
 
Do you mean the link? Or you have downloaded the coded and run it in Processing?

I can run the app via the link on any machine, however I can't run the app in Processing IDE on my Mac but I can run the app on my Fedora machine in the Processing IDE.

The reason for the failure is the opening lines in the constructor for myParser. However I have no idea why this is the case, and can only think it is to do with the differing Java versions?
Re: Fedora Linux and Mac OS X - Java...
Reply #3 - Jun 25th, 2009, 12:57pm
 
can you package the sketch and send me a link? i try it in my processing ide if you like
Re: Fedora Linux and Mac OS X - Java...
Reply #4 - Jun 29th, 2009, 1:57pm
 
Before I do that, I think I may have noticed something. On my Fedora machine where the lastest version of the processing executable file is I created a sub directory called data and within that I placed my data file. This is not the case on my Mac machine.

How would I do the same on my Mac? Would I create it within the /Applications/Processing.app directory?

The code in setup reads:

void setup()
{

 size(800, 600);

 tp = new MyParser("data/HoCMP.xml");

 ...

}

And MyParser constructor has:

public MyParser(String fileName)
   {
       dbf = DocumentBuilderFactory.newInstance();
       
       try
       {
           System.out.println("filename is "+fileName);
           in = getClass().getResourceAsStream(fileName);
                     
           db = dbf.newDocumentBuilder();
           myDom = db.parse(in);
       }
       catch (Exception e)
       {
           System.err.println(e.toString());
       }
       
   }

If you would prefer real code I will sort out an upload to a site.
Re: Fedora Linux and Mac OS X - Java...
Reply #5 - Jun 29th, 2009, 2:08pm
 
In fact here is code showing the problem (I have trimmed out all the "rubbish"):

PFont f;
MyParser tp;
void setup()
{
 size(800,600);
 
}

void draw()
{
   background(0);
   fill(255);
   rect(350,250,100,100);
   tp = new MyParser("data/HoCMP.xml");
   tp.List("Test");
   f = createFont("Serif",18);
   textFont(f);
   fill(0);
   text("Works!!!",370,300);
}


import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.Vector;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.net.URL;

public class MyParser
{
   private Document previous = null;

   protected Document myDom = null;
   protected DocumentBuilderFactory dbf = null;
   protected DocumentBuilder db = null;
   protected InputStream in = null;
   
   private TransformerFactory tranFact = TransformerFactory.newInstance();
   
   public MyParser(String fileName)
   {
       dbf = DocumentBuilderFactory.newInstance();
       
       try
       {
           System.out.println("filename is "+fileName);
           in = getClass().getResourceAsStream(fileName);
                     
           db = dbf.newDocumentBuilder();
           myDom = db.parse(in);
       }
       catch (Exception e)
       {
           System.err.println(e.toString());
       }
       
   }

   public Vector List(String tag)
   {
       Vector a = new Vector();
       NodeList t = myDom.getElementsByTagName(tag);
       if (t.getLength() > 0)
       {
           for (int i = 0; i < t.getLength(); i++)
           {
                  if (i+1 < t.getLength())
                  {
                       if (!(t.item(i).getTextContent().equals(t.item(i+1).getTextContent())))
                       {
                           a.add(t.item(i).getTextContent());
                       }
                  }
                  else
                  {
                      if (!(t.item(i).getTextContent().equals(t.item(i-1).getTextContent())))
                      {
                           a.add(t.item(i).getTextContent());
                       }    
                  }
           }
       }
       return a;  
   }
}
Re: Fedora Linux and Mac OS X - Java...
Reply #6 - Jul 1st, 2009, 1:00pm
 
Doing some more research into this I have found that the line:

in = getClass().getResourceAsStream(fileName);

Expects the file (in this case fileName [data/HoCMP.xml]) to exist in the same place as the class that contains this line.

Now I have tested this using Netbeans and can get it to work, however with the processing ide I cannot work out where this class would exist? I have tried creating the directory within the directory that contains the pde file but still my problem persists.

Any thoughts?
Re: Fedora Linux and Mac OS X - Java...
Reply #7 - Jul 3rd, 2009, 11:47pm
 
this doesn't even work on my ubuntu machine Smiley

try to replace the line
in = getClass().getResourceAsStream(fileName);
with
in = createInput(filename);
(without the "data/" prefix)

this processing command searches the data folder (in the applet or the application) and creates an inputStream for the given file

PS: sorry for the delay Undecided
Re: Fedora Linux and Mac OS X - Java...
Reply #8 - Jul 4th, 2009, 1:09pm
 
Perfect!!!! Thank you very much!  Smiley

I wasn't aware of the createInput function, I am now Cheesy !!!

Thanks again, puzzling how it ever worked on my Fedora machine, not to worry though.
Page Index Toggle Pages: 1