I have a code which works correctly as expected in my command line java tool.
The same code when I added to eclipse does throw some error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot cast from Object to long
On the line :
long statusId = (long)json.get("status_id");
However with javac and java command I run the program with successful output.
WTH eclipse is behaving this way! And this is my first eclipse program, kindly help me out.
Edit:
Code :
public InitOrderResponse connect()
{
Authentication auth = new Authentication();
String response = auth.httpBasicAuth(this.constructUrl(),this.key);
JSONObject json = (JSONObject) JSONValue.parse(response);
String merchantId = (String)json.get("merchant_id");
long statusId = (long)json.get("status_id");
String status = (String)json.get("status");
String orderId = (String)json.get("order_id");
initOrderResponse = new InitOrderResponse();
initOrderResponse.setStatus(status);
initOrderResponse.setOrderId(orderId);
initOrderResponse.setStatusId(statusId);
initOrderResponse.setMerchantId(merchantId);
return initOrderResponse;
}
Your eclipse has error/warnings constraints set to give error for some condition, that is not imposed by Java compiler by default.To change these rules, right click on the project, click on properties. Under 'Java Compiler' menu, go to 'errors/warnings'. There you can set constraints for compiler to give errors/warnings.
The problem was with the Jdk versions. When I changed the jdk to point towards the Sun's JDK. Everything works as expected.
Related
I´m using Krextor to convert XML to RDF. It runs fine from the command line.
I try to run it from Java (Eclipse) using this code.
private static void XMLToRDF() throws KrextorException, ValidityException, ParsingException, IOException, XSLException{
Element root = new Element("person");
Attribute friend = new Attribute("friends", "http://van-houten.name/milhouse");
root.addAttribute(friend);
Element name = new Element("name");
name.appendChild("Bart Simpson");
root.appendChild(name);
nu.xom.Document inputDocument = new nu.xom.Document(root);
System.out.println(inputDocument.toXML());
Element root1 = inputDocument.getRootElement();
System.out.println(root1);
Krextor k = new Krextor();
nu.xom.Document outputDocument = k.extract("socialnetwork","turtle",inputDocument);
System.out.println(outputDocument.toString());
}
I have the following problem problem
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/saxon/CollectionURIResolver
Caused by: java.lang.ClassNotFoundException: net.sf.saxon.CollectionURIResolver
I have included Saxon9he in the classpath, and I have also added manually as a library in the project but the error is the same.
I am the main developer of Krextor. And, #Michael Kay, actually a colleague of Grangel, so I will resolve the concrete problem with him locally.
So indeed the last Saxon version with which I did serious testing was 9.1; after that I haven't used Krextor integrated into Java but mainly used Krextor from the command line.
#Grangel, could you please file an issue for Krextor, and then we can work on fixing it together.
Indeed, #Michael Kay, for a while I had been including more recent Saxon versions with Krextor and updated the command line wrapper to use them (such as to add different JARs to the classpath), but I have not necessarily updated the Java wrapper code.
I have been using Apache CXF 2.7.0 for quite a while now, but recently I had to restructure my project in Eclipse. After I did that, for some reason, I cannot add a "WSAddressingFeature" Feature to the endpoint.
What am I missing??
endpoint.getFeatures().add(new org.apache.cxf.ws.addressing.WSAddressingFeature());
Eclipse is reporting that:
"The method add(Feature) in the type List<Feature> is not applicable for the arguments (WSAddressingFeature)"
This is my full implementation:
String url = "http://localhost:" + m_Port + "/infoburst/handler";
Object implementor = new HandlerImpl();
org.apache.cxf.jaxws.EndpointImpl endpoint = new org.apache.cxf.jaxws.EndpointImpl(implementor);
endpoint.getFeatures().add(new org.apache.cxf.ws.addressing.WSAddressingFeature());
endpoint.publish(url);
org.apache.cxf.endpoint.Server server = endpoint.getServer();
org.apache.cxf.jaxws.JaxWsServerFactoryBean serverFB = endpoint.getServerFactory();
If I remove the line of code that adds the feature, the following error occurs:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cxf.common.util.ReflectionUtil.getDeclaredMethod(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.bindOperation(JaxWsServiceFactoryBean.java:276)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.createOperation(ReflectionServiceFactoryBean.java:1045)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.createOperation(JaxWsServiceFactoryBean.java:642)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.createInterface(ReflectionServiceFactoryBean.java:990)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:481)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:704)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:550)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251)
at org.apache.cxf.jaxws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:155)
at javax.xml.ws.Endpoint.publish(Unknown Source)
at com.infosol.infoburst.XI4Service.HandlerService.publish(HandlerService.java:106)
at com.infosol.infoburst.XI4Service.HandlerService.main(HandlerService.java:42)
This is why I really don't enjoy working in the Java environment...
To fix the ""The method add(Feature) in the type List is not applicable for the arguments (WSAddressingFeature)" error:
Go into "Configure Build Path"
Go to "Order and Export"
Move the "cfx-2.7.0.jar" file to a higher priority, this may take a little trial and error.
Once the CFX file is moved up in priority, the error will go away.
I have this line of code in my Java program:
private final List<PhoneNumber> receivers = new ArrayList<>();
It signifies an error underneath the first < after 'new ArrayList'. ^
I'm running Eclipse and Windows 8 - 32-bit, could this be an encoding problem?
Try this: You have to parametarize the type of object at both sides.
private final List<PhoneNumber> receivers = new ArrayList<PhoneNumber>();
The Diamond Operator, used to reduce the verbosity when using generics was added in JDK 1.7. The fact you're getting a syntax error probably means you're using an older version to compile this piece of code.
Either use JDK 1.7 to compile the code, or change to:
new ArrayList<PhoneNumber>();
This was the solution for me:
Window -> Preferences -> Java -> Compiler -> Compiler Compliance Level: 1.7
this was 1.6 at first.
Had to download Eclipse Indigo RS2 for this one.
In the following code:
public void connect()
{
/*
String selectedPort = "COM1";
String selectedPort = (String)window.cboxPorts.getSelectedItem();
selectedPortIdentifier = (CommPortIdentifier)portMap.get(selectedPort);
*/
}
Eclipse complains that selectedPort cannot be resolved. Why is it even looking inside of a comment?
First, you need to refresh the project.
Second, clean and rebuild. This must be happening as the new class file is not generated for you java file and eclipse is still looking at the previous compiled form.
I have installed the JDK version 1.6 now the code is compiled but throws a run-time error
class Console1
{
public static void main(String args[])
{
System.console().readLine("this is how we give he input to the string");
System.out.println("this is what we want to print:0)");
}
}
Output
exception in thread "main" java.lang.NoClassDefFoundError: Console
It looks like you are running with a different version of Java. Add this as the first line of code to your "application". It will show the java version which is used to run the application.
System.out.println(System.getProperty("java.version"));
I see this is related to your other thread here.
System.console() returns the Console object, which was added in JDK 1.6, you say you have installed jdk 1.6, so one can only assume that your versions of java you are using to compile and run your code are different.
Can you please tell me what you are using to compile the code, and how you are running the code?
In future, please use the same thread you initially posted, it's much easier for people to trace.
Instead of console you can use...
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
String s = bufferRead.readLine();
see example