I have the following code...
public class first
{
public static void main (String[] args)
{
WebSpec spec = new WebSpec().safari();
spec.safari().open("http://www.google.com"); //opens google.com in Safari
}
}
written in eclipse.
WebSpec is underlined in red giving an error saying "cannot be resolved to be a type"
I assume this is because some of the libraries are not in the right spot? I have tried many different things.
What do I need to do?
Be sure to include all .jar's included in the webspec download in your library. There are .jar's in the lib folder and also one .jar in java\dist of webspec. Eclipse allows you to import libraries by highlighting your project then Project > Properties > Java Build Path > Libraries (tab).
Related
I have a running and working Tomcat Project and I want to add a normal Java project into it for better and faster testing. No pages to get fast database outputs and such.
In the WEB-INF/src folder I have added a package with contains my main class and includes some of the other controllers from the project.
EDIT: Moved sources to the /src (as suggested) folder but still the same error.
Right now it is a simple println in a main class. The problem is that eclipse tells me it cannot find the main clas or load it. (right click on the main class file -> runs as -> Java Application)
package mytomcatproj.maintest
import mytomcatproj.othercontroller
public class MyMainClass {
public static void main(String[] args) {
String overval="te";
String overres= othercontroller.getWord(overval);
System.out.println("Test" + overres);
}
}
How can I get the project to run?
Thank you for you help.
I tried every online solution and i still get the same result..i'm trying to get my code to run on a file "distinct.txt" and here is my attempt to run it.
i tried different paths and all give same result.
here is my code
package pset2.sol;
import edu.princeton.cs.algs4.StdIn;
public class Permutation {
public static void main(String[] args){
RandomizedQueue<String> rq = new RandomizedQueue<>();
while (!StdIn.isEmpty()) {
String item = StdIn.readString();
rq.enqueue(item);
}
int k = Integer.parseInt(args[0]);
for(int i = 0; i < k; i++){
System.out.println(rq.dequeue());
}
}
}
My guess is that your source-folder is not set correctly.
Try File -> Project Structure -> Modules -> (tab) Sources -> Mark as: Sources.
That fixed the problem for me after importing an Eclipse Project.
You have to make sure that the "Project compiler output" value is set, in Project Structure > Project, and that the module's Compiler output points to a valid path:
Ideally, you should always use the green button from IntellIJ. You can set the Edit Configurations to give the path to the file. I don't know about reading in the file from stdin through there, though.
Your problem is not IntelliJ, though, it's the CMD.
First, make sure you are in the right folder.
Run cd /path/to/compiled_files to see that you are at the parent of the pset folder.
pset
/sol2
Permutation.class
Then, you'll likely need a classpath to have the other classes within the pset.sol2 package to be resolved.
java -cp . pset.sol2.Permutation
More details: What does "Could not find or load main class" mean?
In intellij, choose Run. | Edit Configurations from the main menu.
A bit late to the party here, but I found that my Main file (in the source file), was missing the ".java" extension, even though the file looked fine in the intelliJ project explorer.
However on close inspection, I noticed that the file type in /out/ was not a class file (i.e. did not have the blue circle with a "C" in).
I think this could be because I created the "main" file in my source folder, before I marked that folder as source in the project settings, and the file type created was undefined somehow...
To fix, I renamed the Main file to Main.java (in finder), and rebuilt the project from the build menu.
I am facing a problem while i am trying to compile a code at eclipse in java. The code is the following:
public class New {
public static void main(String[] args){
System.out.println("hello world");
}
}
Parts that have errors are New, String and System. I have checked at error list and the description for error's is like:
Unable to create editor ID
The file does not exist
Any idea why this is happening?
Your project has or classes maybe has beeing dissapeared.
I can give you a possible solution
Solution: Shut down Eclipse IDE Start Eclipse IDE (with -clean to be super-safe) Reimport all projects (UPDATE: Just use File->Import->Existing Project into Workspace and browse your workspace/project directory)
i'm trying to compile a Java Web Service client with the windows console but there are 100 errors. The client has been made in eclipse, and in it's console it works good. Here it is the code:
public static void main (String[] args)throws Exception{
try{
MireiaUPMPortTypeProxy proxy = new MireiaUPMPortTypeProxy();
proxy.setEndpoint("http://138.4.47.33:8087/axis2/services/MireiaUPM.MireiaUPMHttpSoap11Endpoint/");
String respuesta=proxy.getNER("[content]David is in the office.[/content]", "en");
System.out.println(respuesta);
}catch(Exception e3){
e3.printStackTrace();
}
}
}
When i compile the kind of errors that appear are: Cannot find symbol and org.apache axis.constants does not exist
Could you help me? i'm new at using web services and i'm so lost. The extrange thing for me is that it runs well in the eclipse console, but it doesn't compile.
it runs in Eclipse simply because dependent libs (jars!) are set in eclipse build path.
to be able to compile from OS console/terminal, you have to set classpath correctly. check eclipse build path (right click on project and look for this menu) and add those dependencies in your console command.
Please make sure your all related jar files are on class path when compiling your class files.
How do I import "HttpClient" in Eclipse? I downloaded HttpClient from http://hc.apache.org/downloads.cgi just now. I added it to my Eclipse new java project and want to run a example copy from website.
This example uses import org.apache.commons.httpclient.*; But, what pity is, it shows that Eclipse can't resolve this.
Now, I want to know the right way to import new released HttpClient to my project.
Is it necessary to add some jar to classpath? What is it?
This is the whole example I run. I guess new released "HTTPClient" changed its import jar, is it true?
package http.demo;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class SimpleHttpClient {
public static void main(String[] args) throws IOException {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost( "www.imobile.com.cn" , 80, "http" );
method = getPostMethod();
client.executeMethod(method);
System.out.println(method.getStatusLine());
Stringresponse=newString(method.getResponseBodyAsString().getBytes("8859_1"));
System.out.println(response);
method.releaseConnection();
}
private static HttpMethod getGetMethod(){
return new GetMethod("/simcard.php?simcard=1330227");
}
private static HttpMethod getPostMethod(){
PostMethod post = new PostMethod( "/simcard.php" );
NameValuePair simcard = new NameValuePair( "simcard" , "1330227" );
post.setRequestBody( new NameValuePair[] { simcard});
return post;
}
}
It works, it Solved:
first download file JAR from web apache https://hc.apache.org/downloads.cgi.
extract file zip
open your eclipse project
Do right click libs on the Package Explorer and choose Build Path -> Configure Build Path
Choose Java Build Path on the left side box
Click tab Libraries.
Add External JAR, choose your extracted file on point (2)
You may choose all file JAR on extracted file, it depends on your imported at your project.
You drag the jar file to your project so you can see it inside Eclipse.
To give it special meaning to Eclipse, right click on the jar file inside Eclipse and select Build Path -> Add to Build Path.
Now your imports should resolve properly.
Go to:
https://hc.apache.org/downloads.cgi
download the *****.tar.gz file
extract it
go inside the lib folder, there you'll find all the JARs
open Eclipse, right click on your project -> Properties -> Java Build Path ->
Libraries tab -> Add External JARs - > choose all the JARs in lib (step 4)
to test I recommend you try to run some code that uses this library like:
http://www.mkyong.com/java/apache-httpclient-examples/
you'll probably see a red underline, hover it and choose Import.....
good luck