1

I have installed both jdk6 (jdk1.6.0_26) and jdk7 (jdk1.7.0_25). I have two following java classes:

1st java file:

package code.google.com.p.selenium;
import org.openqa.selenium.WebElement;
public class GoogleSearchPage {
    // Here's the element
    private WebElement q;

    public void searchFor(String text) {
        // And here we use it. Note that it looks like we've
        // not properly instantiated it yet....
        q.sendKeys(text);
        q.submit();
    }
}

2nd java file:

package code.google.com.p.selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.PageFactory;

public class UsingGoogleSearchPage {
    public static void main(String[] args) {
        // Create a new instance of a driver
        WebDriver driver = new HtmlUnitDriver();

        // Navigate to the right place
        driver.get("http://www.google.com/");

        // Create a new instance of the search page class
        // and initialise any WebElement fields in it.
        GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class);

        // And now do the search.
        page.searchFor("Cheese");
    }
}

I am using Eclipse Indigo. In eclipse, I did the following steps:

  1. Right click on UsingGoogleSearchPage.java
  2. Click Run As->Java Application

The program was not executed. An error was occurred (Please see the image). enter image description here

0

3 Answers 3

2

I think you are very new in Eclipse and Java. You need to tell the JVM about your main class. It means you need to select the class which is containing your public static void main(...) method. From which the execution will start. You can do this from eclipse Run Configurations. Steps -

1) Right click on the class

2) Run As -> Run Configurations...

3) From the first tab (Main tab) select your class which is containing your main method

4) Press Apply and Run

Hope it will work.

Sign up to request clarification or add additional context in comments.

3 Comments

Can you try to run one simple Class with only the main method? From the main method just print some string. If your configurations are correct then it should work.
I ran the simple class: package code.google.com.p.selenium; public class TestTest { public static void main(String args[]){ System.out.println("I'm bad boy"); } }
One information is important I think. I have installed both jdk6 (jdk1.6.0_26) and jdk7 (jdk1.7.0_25)
0
  1. Check if the .class file exists in your output folder.To know your output folder Right Click on Project->Properties->Java Build Path(Check at bottom).

  2. Check if Project->build Automatically is checked in the menu.

  3. Check if the UsingGoogleSearchPage class is in src folder or not.Right Click on Project->Properties->Java Build Path(Check source tab).

  4. Or delete the Run Configuration. See here.

1 Comment

Thanks for cooperation. Let me apply that
0

I have installed both jdk6 (jdk1.6.0_26) and jdk7 (jdk1.7.0_25) in my PC.

  1. Right click on project -> Click Properties
  2. Click "Java Build Path" at left panel
  3. Select Libraries tab at right panel and observe JRE System Library

Observation: JRE System Library was set as JavaSE-1.6

I changed JavaSE-1.6 to JavaSE-1.7 as Execution environment on the eclipse as follows:

  1. Double click on JRE System Library [JavaSE-1.6]
  2. Set the value "JavaSE-1.7 (jre7)" on Execution environment combo -> Click Finish button
  3. Finally click OK at Java Build Path pop up
  4. Now run the java application

Application was executed well

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.