Results 1 to 10 of 10
  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default How do I call a 2nd script?

    I have made a program.
    And that one does one thing.
    Like writing a XML file.

    Now I have a 2nd program that can read a XML file.

    But how do I run program1 and then let him run program2 right after?
    (Like how do execute another .java in a .java file)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Do you have two classes for reading and writing your XML files?
    Yes, I have.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    And do you know how to call a method in a class right?
    Yes.
    Goes that the same way?

  6. #6
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    I now got:

    Java Code:
     
    public class XMLwegschrijven extends Test {
    	public static void main(String[] args) throws Exception {
    And file2 (test file) I try to read in here:

    Java Code:
     
    public class Test {
    	public static void main(String[] args) { 
    	System.out.println("Hi"); 
    	}
    }
    But here I get the next error:

    XMLwegschrijven.java:18: main(java.lang.String[]) in XMLwegschrijven cannot override main(java.lang.String[]) in Test; overridden method does not throw java.lang.Exception
    public static void main(String[] args) throws Exception {
    ^
    1 error
    ./Test.java:2: <identifier> expected
    System.out.println("Hi");
    ^
    ./Test.java:4: 'class' or 'interface' expected
    }
    ^
    ./Test.java:4: 'class' or 'interface' expected
    }
    ^
    ./Test.java:2: cannot find symbol
    symbol : class out
    location: class java.lang.System
    System.out.println("Hi");
    ^
    4 errors
    copy output
    Program exited with code #1 after 0.42 seconds.
    Last edited by Lund01; 02-15-2011 at 12:39 PM.

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Are you trying to put a main method inside a class that extends another with a main method? Don't do that. You should have only one main method. You can put it in a separate class to keep things organized.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Having your main method to throw Exception is itself a bad idea. That way, if any exception occurs, it leads to JVM crash and you won't ever come to know what went wrong.

    Better way, use try/catch blocks and handle the risks.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Jquery pop out script
    By fOmey in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 03:13 AM
  2. call by value and call by reference in java
    By sandeepsai39 in forum New To Java
    Replies: 7
    Last Post: 08-12-2010, 12:03 PM
  3. How to call php script using Java
    By narik in forum New To Java
    Replies: 2
    Last Post: 01-22-2010, 06:08 PM
  4. Call java Methods from Python Script
    By hofsoc in forum New To Java
    Replies: 1
    Last Post: 02-18-2009, 05:47 PM
  5. [B] How to call Perl script from Java [/B]
    By JavaEmpires in forum Advanced Java
    Replies: 7
    Last Post: 12-19-2008, 04:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •