Results 1 to 2 of 2
  1. #1
    New-to-this is offline Member
    Join Date
    Aug 2009
    Rep Power

    Default help calling 1 .java from another.

    It's late and I am tired...

    I cannot get this right, please help. I am using Eclipse 3.5.0 and JRE 6
    C:\Program Files\Java\jre6\bin\client\jvm.dll
    Classpath is
    <?xml version="1.0" encoding="UTF-8"?>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="C:/Documents and Settings/Phil/workspace/google/src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="C:/eclipse/testng-5.10-jdk14.jar"/>
    <classpathentry kind="lib" path="C:/eclipse/testng-5.10-jdk15.jar"/>
    <classpathentry kind="lib" path="C:/Selenium-remote-control-1.0.1/selenium-remote-control-1.0.1/selenium-java-client-driver-1.0.1/selenium-java-client-driver-test-sources.jar"/>
    <classpathentry kind="lib" path="C:/Selenium-remote-control-1.0.1/selenium-remote-control-1.0.1/selenium-java-client-driver-1.0.1/selenium-java-client-driver.jar"/>
    <classpathentry kind="lib" path="C:/Selenium-remote-control-1.0.1/selenium-remote-control-1.0.1/selenium-java-client-driver-1.0.1/selenium-java-client-driver-sources.jar"/>
    <classpathentry kind="lib" path="C:/Selenium-remote-control-1.0.1/selenium-remote-control-1.0.1/selenium-java-client-driver-1.0.1/selenium-java-client-driver-tests.jar"/>
    <classpathentry kind="output" path="bin"/>

    all my .java is in C:/Documents and Settings/Phil/workspace/google/src

    this is my first program....

    import java.applet.Applet;
    import java.awt.Button;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Label;
    import java.awt.Rectangle;
    import java.awt.TextField;
    import java.awt.event.ActionEvent;

    public class UserForm extends Applet {
    String strrecordnolow;
    String strrecordnohigh;
    TextField txtrecordnolow = new TextField();
    TextField txtrecordnohigh = new TextField();
    Label lblrecordnolow = new Label();
    Label lblrecordnohigh = new Label();
    Button btnOK = new Button();
    Button btnCancel = new Button();

    //Construct the applet

    public UserForm()


    //Initialize the applet

    public void init() {
    try {
    catch (Exception e) {

    private void jbInit() throws Exception {
    lblrecordnolow.setBounds(new Rectangle(21,13,118,25));
    lblrecordnohigh.setBounds(new Rectangle(21,38,118,25));
    lblrecordnolow.setText ("From:");
    lblrecordnohigh.setText ("To:");
    btnOK.setBounds(new Rectangle(81, 219, 100, 40));
    btnOK.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    btnCancel.setBounds(new Rectangle(224, 217, 100, 41));

    btnCancel.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {

    this.setSize(new Dimension(400, 275));
    txtrecordnolow.setBounds(new Rectangle(154, 12, 219, 23));
    txtrecordnohigh.setBounds(new Rectangle(154, 35, 219, 23));
    this.add(txtrecordnolow, null);
    this.add(txtrecordnohigh, null);
    this.add(lblrecordnolow, null);
    this.add(lblrecordnohigh, null);
    this.add(btnOK, null);
    this.add(btnCancel, null);


    void btnOK_actionPerformed(ActionEvent e) {
    strrecordnolow = txtrecordnolow.getText();
    strrecordnohigh = txtrecordnohigh.getText();
    try {
    Runtime.getRuntime().exec( "" );

    } catch (IOException e1) {
    // TODO Auto-generated catch block


    void btnCancel_actionPerformed(ActionEvent e) {
    txtrecordnolow.setText ("");
    txtrecordnohigh.setText ("");


    And this is my second...

    import java.sql.*;

    public class ReadData<New> {

    static Connection con;
    static Statement stmt;
    static ResultSet dataread;
    static int testref;
    static int recordnohigh;
    static int recordnolow;
    static int recordnocurrent;

    public static void main(String[] args) throws java.lang.ClassNotFoundException {

    UserForm UserForm = new UserForm();
    String newvariable = UserForm.strrecordnolow;
    System.out.println (newvariable);

    //step 1: load driver

    //step 3: establish connection

    //retrieve data

    //close all resources

    // load a driver
    static void loadDriver() {
    try {
    //step 2: Define connection URL

    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");

    // make a connection step 3: establish connection
    static void makeConnection() {
    //for how to set up data source name see below.
    String dsn = "PhilsDataSource";
    String url = "jdbc:odbc:" + dsn;
    try {
    con = DriverManager.getConnection(url, "", "");
    }catch(SQLException ex) {
    System.err.println("database connection: " + ex.getMessage());

    private static void println(String string) {
    // TODO Auto-generated method stub


    //retrieve data from table Users
    static void retrieveData() {
    try {//try begins
    recordnolow = 1;
    recordnohigh =5;
    recordnocurrent = recordnolow;
    //Read starts at lowest figure in range and increments up to highest in range
    //All data read between these points
    do {
    String getdata="SELECT * FROM Users " + "WHERE TestRef = " + recordnocurrent;
    //process the results.
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE, ResultSet.CONCUR_UPDATABLE);
    dataread = stmt.executeQuery(getdata);
    // System.out.println (getdata);uncomment this line for Select statement info;
    //Reads all fields in dbase - specifiy further ones here
    testref = dataread.getInt("TestRef");
    String Firstname = dataread.getString("Firstname");
    String Surname = dataread.getString("Surname");
    System.out.println(testref + ". " + Firstname + " " + Surname);
    recordnocurrent = recordnolow;
    }while (recordnolow <= recordnohigh);

    }//try ends
    catch(SQLException ex)
    {//catch begins
    System.err.println("RetrieveData: " + ex.getMessage());
    }//catch ends

    }//static void retrieve data ends here

    //close statement and connection
    //step 7: close connection, etc.
    static void closeAll() {
    try {
    } catch(SQLException ex) {
    System.err.println("closeAll: " + ex.getMessage());

    All I need to be able to do is call the from and pass the two variables recordnolow and recordnohigh through to, I then want to use these two variables to form the basis of my SQL selection in I have managed to make the two scripts work independantly of each other but I cannot get them talking. When I run them through Eclipse to execute, my UserForm works right up until :

    try {
    Runtime.getRuntime().exec( "" );

    } catch (IOException e1) {
    // TODO Auto-generated catch block

    Where it crashes with the error Cannot run program "": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at UserForm.btnOK_actionPerformed(
    at UserForm$1.actionPerformed(
    at java.awt.Button.processActionEvent(Unknown Source)
    at java.awt.Button.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at Source)
    Caused by: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 17 more


    I have two issues,
    1) The crash mentioned above - why can the system not find the file
    2) How to move the two variables across from UserForm to ReadData, I am guessing - am I on the right lines with
    UserForm UserForm = new UserForm();
    String newvariable = UserForm.strrecordnolow;
    System.out.println (newvariable);

    thanks for the help folks. Sorry for the long post.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    First of all, please use the dark color when you post something again here in the forum. The color you've used is really hard to look at. And also please use code tags when posting code snippets here in the forum. Formatted codes are easy to read.

    Java Code:
    Runtime.getRuntime().exec( "" );
    You cannot do this, how can you run a *.java file this way. Just think about in simple way. *.java file contain the source code. Can you run it, no. Why? Because the computer cannot understand those text and all in the file. What you have to do? Compile the source file and create the *.class file. It's understandable by the computer. Anyway, you cannot run a *.class file as well in this way. Did you read the Java doc about the Runtime class?

    And also, read bit more about objects in Java and member access. It'll help you find the answer in second topic you mention. Actually there are no two things.

Similar Threads

  1. Calling java functions from c++
    By khajalid in forum New To Java
    Replies: 13
    Last Post: 10-12-2010, 11:50 PM
  2. Calling a variable from a different java class
    By jdiesel in forum New To Java
    Replies: 4
    Last Post: 01-09-2009, 02:12 AM
  3. calling java virtual machine
    By many in forum New To Java
    Replies: 5
    Last Post: 12-01-2008, 11:06 PM
  4. calling a java application from another
    By kratoras in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 03:54 AM
  5. Calling Java Function through JSP
    By Vikrant Pawar in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-06-2008, 07:28 AM

Posting Permissions

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