error while trying to generate stub file - java

When i try to generate a stub file using :rmic RemoteMethodImpl
I get the following error :
error: File .\RemoteMethodImpl.class does not contain type RemoteMethodImpl as expected, but type InterfaceImplementation.RemoteMethodImpl. Please remove the file, or make sure it appears in the correct subdirectory of the class path.
error: Class RemoteMethodImpl not found.
2 errors
What error is this ? Why do i get this ?
Upon the request of # Shashank Kadne
package InterfaceImplementation;
import Interfaces.RemoteMethodIntf;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import Design.Main_Design_Client;
/**
*
* #author program-o-steve
*/
public class RemoteMethodImpl extends UnicastRemoteObject implements RemoteMethodIntf{
public RemoteMethodImpl() throws Exception{}
#Override
public void send(String IP,String Message) throws RemoteException {
Main_Design_Client mdc = new Main_Design_Client();
mdc.jTextArea1.setText("<html><b>Message from :</b></html>" + IP);
mdc.jTextArea1.setText("<html><b>Message :</b></html>" + Message);
}
}

I am assuming you are in a directory just outside "InterfaceImplementation" folder.
Execute : rmic InterfaceImplementation.RemoteMethodImpl

Yes, I was trying
% rmic GumballMachine
but changed after reading it from
% rmic gumball\GumballMachine
to
%rmic gumball.GumballMachine
which works fine. Sometimes, I wonder what a blockhead I am!!

When i try to generate a stub file
Stop right there. You haven't needed to do that for about eight years.
public RemoteMethodImpl() throws Exception{}
Just change that to call super() and you won't need a stub at all. See the preamble to the Javadoc for java.rmi.server.UnicastRemoteObject.

Related

Does the NullPointerException really depend on the location of the class?

I have two classes in a Maven project, which contain the same code (except for their name). The code shall later create a new class with Javassist based on a csv-file.
The first one CsvParser is placed in the src/main/java/csvParser package. The second one TestCsvParser is placed in the src/test/java/csvParser package. In both packages the same file assistant.csv is placed.
When I run the one from the main directory (CsvParser) I get a java.lang.NullPointerException but when I run TestCsvParser, placed in the testdirectory the same code works fine.
Why is it like that? (Or do I just not see something? ;) )
CsvParser:
package csvParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CsvParser {
public static void main(String[] args) throws IOException
{
createClass("/assistant.csv");
}
/**
* Create a class from a csv-file.
*/
private static void createClass(String input) throws IOException {
try(BufferedReader stream = new BufferedReader(new InputStreamReader(
CsvParser.class.getResourceAsStream(input))))
{
// Create class based on csv-file.
}
}
}
TestCsvParser:
package csvParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestCsvParser {
public static void main(String[] args) throws IOException
{
createClass("/assistant.csv");
}
/**
* Create a class from a csv-file.
*/
private static void createClass(String input) throws IOException {
try(BufferedReader stream = new BufferedReader(new InputStreamReader(
TestCsvParser.class.getResourceAsStream(input))))
{
// Create class based on csv-file.
}
}
}
The exception
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at csvParser.CsvParser.createClass(CsvParser.java:19)
at csvParser.CsvParser.main(CsvParser.java:11)
I believe this question is not a duplicate of a question like What is a NullPointerException because:
The NullPointerException occurs based on the location of the class and the resource referred to. So it's more about directory structures and Mavens targetdirectory.
Thanks for your time!
Finally I found the error. I added the assistant.csv beside the two classes (CsvParser and TestCsvParser). But in both cases this file is not added to the target directory.
The reason why it was working in TestCsvParser is an additional assistant.csv in the ../test/resource/ directory. In fact the two conditions which I described missed this fact and therefore you could not reconstruct my error fully. I'm sorry for that.
To have a working example the resource files both for main and test have to placed within the resource folder instead of beside the class.
Thanks for your help, especially Kalaiselvan A.
It will depend on location of "/assistant.csv" file and if it's not found, you will get NPE. The path will be dependent on your class location since you are calling CsvParser.class.getResourceAsStream..

Rserve - Eclipse & Java

Hi I am setting up rserve based on the instructions on this website.
http://www.codophile.com/how-to-integrate-r-with-java-using-rserve/
However in eclipse I am getting an error when using 'eval'
double d[] = c.eval("rnorm(10)").asDoubles();
error - 'The method eval(String) is undefined for the type RConnection'
The JARS have been correctly loaded into the build path and rserve is running, however I cannot figure out why only the eval function is causing an issue.
In addition to this the import of ...
import org.rosuda.REngine.Rserve.RConnection;
causes an error - 'The import org.rosuda.REngine.Rserve.RConnection conflicts with a type defined in the same file'
does anyone have any idea why this is the case? Thanks
all imports :
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
public class RConnection {
public int[] mean(String a[]) {
setupR();
return null;
}
public void setupR(){
try {
/* Create a connection to Rserve instance running
* on default port 6311
*/
RConnection c = new RConnection();// make a new local connection on default port (6311)
double d[] = c.eval("rnorm(10)").asDoubles();
org.rosuda.REngine.REXP x0 = c.eval("R.version.string");
System.out.println(x0.asString());
} catch (RserveException e) {
e.printStackTrace();
} catch (REXPMismatchException e) {
e.printStackTrace();
}
}
}
By using import org.rosuda.REngine.Rserve.RConnection; you are tying to make RConnection known in the local namespace.
However, you already defined a class called RConnection locally.
Please rename your class RConnection, and you should be able to import org.rosuda.REngine.Rserve.RConnection.

GXT 3 XTemplate: Custom Formatter - ClassNotFoundException

I am trying to use a custom formatter to turn a boolean into "Yes" or "No" and have run into a roadblock.
My IDE (Eclipse) does not indicate any errors but when I try to compile I receive
[ERROR] Annotation error: cannot resolve foobar.client.formatter.YesNoFormatter - exception: ClassNotFoundException
followed by a few other exceptions that appear to stem from this exception. I understand what a ClassNotFoundException indicates however I cannot figure out why I would be getting it since, as my code shows, the YesNoFormatter class is located in foobar.client.formatter and I can access it through
GWT.log("True: " + YesNoFactory.getFormat().format(Boolean.TRUE);
I am using GXT 3.1.0 and GWT 2.6.1.
Could anybody have an idea of why I am getting this exception? The example given at http://docs.sencha.com/gxt-guides/3/utility/xtemplates/XTemplates.html doesn't mention anything (as far as I can see) about these classes needing to be in specific locations so I am at a loss.
EntryPoint:
package foobar.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.sencha.gxt.core.client.XTemplates.FormatterFactories;
import com.sencha.gxt.core.client.XTemplates.FormatterFactory;
public class TestClass implements EntryPoint {
#FormatterFactories(#FormatterFactory(factory=YesNoFactory.class, name="yesNo"))
public interface Renderer extends XTemplates {
#XTemplate(source="yesNo.html")
SafeHtml render(Boolean b);
}
#Override
public void onModuledLoad() {
GWT.log("True: " + YesNoFactory.getFormat().format(Boolean.TRUE);
Renderer r = GWT.create(Renderer.class);
Window.alert(r.render(true).asString());
}
}
YesNo:
package foobar.client.formatter;
import com.sencha.gxt.core.client.XTemplates.Formatter;
public class YesNo implements Formatter<Boolean> {
#Override
public String format(Boolean data) {
if (data == null) {
return null;
}
return (data) ? "Yes" : "No";
}
}
YesNoFactory:
package foobar.client.formatter;
public class YesNoFactory {
public static YesNo getFormat() {
return new YesNo();
}
}
in foobar
<?xml version="1.0 encoding="UTF-8"?>
<module>
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.sencha.gxt.GXT'/>
<entry-point class='foobar.client.TestClass'/>
<source path='client'/>
</module>
foobar/client/yesNo.html:
{b:yesNo()}
My formatter classes (YesNo and YesNoFactory) apparently have to be in a location that gets compiled prior to compiling the client-side code. After I moved these classes to my 'shared' package - the package that houses code used by the client and server - everything worked.
This was not obvious in the XTemplates portion of the guide at http://docs.sencha.com/gxt-guides/3/utility/xtemplates/XTemplates.html which does not seem to specify where the files used for custom formatters need to be located. Maybe that should have been obvious but not to me.

GWT.log throwing error

I am new to GWT and trying to build a sample application. Here is my EntryPoint class.
package com.google.gwt.sample.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
public class TalkToServer implements EntryPoint {
public TalkToServer() {}
public void onModuleLoad() {
HTTPRequest.asyncGet
(GWT.getHostPageBaseURL() + "person.xml",
new ResponseTextHandler() {
public void onCompletion(String responseText) {
GWT.log("some log message");
}
});
}
}
The error here is -
log(java.lang.String,java.lang.Throwable) in com.google.gwt.core.client.GWT cannot be applied to (java.lang.String)
I have checked gwt's javadoc and found that log can take string as argument. I am not able to figure out why log is throwing this error. Please let me know if I am missing something.
Try using
GWT.log("some log message", new Throwable())

Why isn't this Java jar working?

When I run the code below I get the following error.
C:\Documents and Settings\BOS\Desktop\test>java -jar test.jar
Exception in thread "main" java.lang.NullPointerException
at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
I've got these files in \test directory = crimson.jar robosuite-api.jar and test.jar.
Here is the example they give to launch a robot?
import com.kapowtech.robosuite.api.java.rql.*;
public class SimpleRunRobot {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: RunRobot <robotURL>");
System.exit(1);
}
try {
// Run the robot
RQLResult result =
RobotExecutor.getRobotExecutor().execute(args[0]);
// Output the results
System.out.println(result);
}
catch (RQLException e) {
System.out.println("An error occurred: " + e);
}
}
}
Why is this giving me that Unknown Source error?
package robosuite.robots;
import com.kapowtech.robosuite.api.java.rql.RQLException;
import com.kapowtech.robosuite.api.java.rql.RQLResult;
import com.kapowtech.robosuite.api.java.rql.RobotExecutor;
import com.kapowtech.robosuite.api.java.rql.construct.RQLObjects;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
* <p>
* This is an autogenerated class. It has been generated from the
* <code>library:/test.robot</code> file.
*
* #author RoboSuite
*/
public class Test {
// ----------------------------------------------------------------------
// Class fields
// ----------------------------------------------------------------------
private static final String ROBOT_URL = "library:/test.robot";
private static final RobotExecutor ROBOT_EXECUTOR = RobotExecutor.getRobotExecutor(SingletonRQLEngine.getInstance());
private static final Converter CONVERTER = Converter.getInstance();
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
/**
* Creates a new Test instance that can be used to execute the
* <code>library:/test.robot</code>.
*/
public Test() {
}
// ----------------------------------------------------------------------
// Instance methods
// ----------------------------------------------------------------------
/**
* Executes this robot.
*
* #param test an input object to the robot.
* #return an array of output objects.
* #throws java.io.IOException if the execution fails for some reason.
*/
public Testst[] run(Test0 test) throws java.io.IOException {
try {
// Prepare input objects
List parameters = new ArrayList();
parameters.add(test);
RQLObjects inputObjects = CONVERTER.convertBeansToRQLObjects(parameters);
// Run robot
RQLResult rqlResult = ROBOT_EXECUTOR.execute(ROBOT_URL, inputObjects);
// Extract output objects
RQLObjects outputObjects = rqlResult.getOutputObjects();
List result = CONVERTER.convertRQLObjectsToBeans(outputObjects);
return (Testst[]) result.toArray(new Testst[result.size()]);
} catch (RQLException e) {
throw new IOException(e.toString());
}
}
/* ------------------------------------------------------------------- */
}
If your using Java 7, Read this.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7067922
Try
java -cp test.jar
include your other .jar files also
If you are using a manifest file make sure you have defined your main class.
for e.g.
Main-Class: test.MyApp
You have to add the name of the class having main() method in META-INF/manifest file.
Here is the link with more information :
http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html
Thanks.
Why is this giving me that Unknown Source error?
The "unknown source" messages are not an error. It is the JVM telling you that the code that you are executing was compiled without any debug information; e.g. with the -gLnone option. As a result, the source file names and line numbers that would normally be included in the stacktrace are not available.
In this case, the code is some platform specific stuff that is internal to the JVM. Don't worry about it ...

Categories

Resources