Rascal module not linking to Java class - java

I'm attempting to create a Socket library in Rascal to operate a Java TCP socket class.
For this the following basic setup is used: (src)>(Network)>(Socket.java, Socket.rsc)
[1]: https://i.stack.imgur.com/a66RS.png
When attempting to import the Network::Socket module into a Rascal Terminal the following error occurs: "Cannot link method Network.Socket because: class not found"
The Rascal module:
module Network::Socket
#javaClass{Network.Socket}
public java str tester();
The Java class:
package Network;
import io.usethesource.vallang.IString;
import io.usethesource.vallang.IValueFactory;
public class Socket {
private final IValueFactory values;
public Socket(IValueFactory values){
this.values = values;
}
public IString tester() {
return values.string("lol");
}
}
Please enlighten me why the linking between the module and class is not working, I dont see the issue.
Closing and opening a new terminal like suggested in Referencing a Java file in Rascal did not fix the issue.

The fault laid in some metadeta of the eclipse project being faulty.
Creating a new project with the exact same setup and files made it work.
Edit: Believed cause of error is renaming the project

Related

java.lang.UnsatisfiedLinkError: Error looking up function

I'm trying to utilize a .dll written in visual basic. I didn't write it so don't have the source code to it. I can load it ok and display the methods inside, but get "java.lang.UnsatisfiedLinkError: Error looking up function" when trying to call one. Here is my code:
package dlltest;
import com.sun.jna.Library;
import com.sun.jna.Native;
import java.lang.reflect.Method;
import java.util.Collection;
public class DllTest {
public interface TC2005 extends Library {
public boolean TCEnabled();
}
public static void main(String[] args) {
TC2005 tc2005 = (TC2005)Native.loadLibrary("TC2000Dev",TC2005.class);
Method[] methods = tc2005.getClass().getDeclaredMethods();
for (Method method:methods) System.out.println(method);
System.out.println("TCEnabled="+tc2005.TCEnabled());
}
}
Here is the output:
public final boolean com.sun.proxy.$Proxy0.TCEnabled()
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'TCEnabled': The specified procedure could not be found.
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:345)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:325)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at com.sun.proxy.$Proxy0.TCEnabled(Unknown Source)
at dlltest.DllTest.main(DllTest.java:70)
There are many more functions and output but just showing one for clarity.
Been reading posts on the subject all day with no joy. Some talk about compilers mangling the method names and hence need for a FunctionMapper code. To get the real method names everyone says to use Dependency Walker. Tried using that to load the .dll Lots of errors. Also tried loading a .exe that uses the .dll and then running the Profiler option in DW. That locks up the program. (Not Responding).
Suggestions?
Cross check your version. You need function which is not present in loaded .dll . Such cases can be seen with incorrect version.

Why do I need package line in my class file while coding java in Eclipse?

So my first time using Eclipse doing an elementary program. I noticed that in Eclipse, you cannot compile a single class file. Rather you need to create a project on top of that. So I did create a project and created a class under the project. I noticed the code
package PackageName;
at the top of the class file. And if I delete the file and run the file, it gives me errors. May anyone answer me why is this happening? Thanks.
My code:
public class CSYes {
public static void main(String[] args)
{
System.out.println("Computer Science, Yes!!!!");
System.out.println("=========================");
}
}
Error Message:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at proj1.CSYes.main(CSYes.java:3)
However, If I have
package proj1;
public class CSYes {
public static void main(String[] args)
{
System.out.println("Computer Science, Yes!!!!");
System.out.println("=========================");
}
}
It works perfectly fine.
The Eclipse IDE encourages you to use packages. In general, it's a good idea. I'd encourage you to use packages, too.
It is NOT, however, a requirement. It sounds like you inadverantly created a "proj1" package when you created the project and/or .java class. Whoops!
To fix the problem, simply a) delete the package reference in your .java source, then b) move the .java file OUT of "/src/proj1" and put in directly under "/src" (the "default package").
... OR, EASIER ...
Delete the entire source (both CSYes.java and proj1)
File > New > Java Class > Name= CSYes; leave package "blank" (i.e. "default package")
Copy/paste your code back into CSYes.
Voila! Done :)

ClassNotFoundException when loading a class at runtime

Using the Bukkit-API I'm currently trying to create a plugin which can compile java code of a given pastebin link at runtime and execute that code. Everything is working so far except for one thing: I'm getting a ClassNotFoundException when I'm trying to access one of the already loaded plugins. (I'm not getting an exception when I'm using Bukkit-API methods!)
All plugin jars have been added to the classpath; it currently looks like this:
/home/cubepanel/test-network/jars/craftcubbit.jar:/home/cubepanel/test-network/servers/ProHub/plugins/MultiCubeHub.jar:/home/cubepanel/test-network/servers/ProHub/plugins/MultiCubeCore.jar:
The classes I tried to load dynamically:
ClassNotFoundException for MutliCube
import be.multicu.core.MultiCube;
public class Test{
public void debug() {
System.out.println(MultiCube.getInstance());
}
}
Working
import org.bukkit.Bukkit;
public class Test{
public void debug() {
System.out.println(Bukkit.getClass().getName());
}
}
Sourcecode of RuntimeCompiler.java: http://paste.multicu.be/axigofekip.avrasm (It's a bit long, thats why I used a pastebin link)
I also noticed that I'm getting an compilation error when I removed the classpath of MultiCube.jar which means that the classpath must be correct since the sourcecode can be compiled.
EDIT: I was able to fix it by adding MultiCube.class.getClassLoader() as an argument in the constructor of my URLClassLoader

How to access DLL methods in Java code using JNA?

By running System.loadLibrary("myAPI"), I verified that the DLL file "myAPI.dll" can be successfully loaded into my Eclipse Java project. Now I need to call methods specified inside this DLL file from my Java code. To do this, I added JNA to my Java project. Then I wrote the below-given code snippet that should be able to get instances of classes IProject and ProjectFactory (specified in the DLL file).
I still don't understand how to properly implement this with JNA. I checked different threads, e.g. this one, but the ones I checked don't provide an answer. Any help is highly appreciated. Thanks.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MyClass {
public interface myAPI extends Library {
//...
}
void LoadProj() {
myAPI api = (myAPI) Native.loadLibrary("myAPI",myAPI.class);
String fileName = "xxx.sp";
IProject project; // this is wrong but shows what I am trying to do
try {
project = ProjectFactory.LoadProject(fileName);
}
catch (Exception ex) {
MessageBox.Show(this, ex.Message, "Load failure");
}
}
}
Not sure what problem you are facing but as a practice your myAPI interface should declare all the methods verbatim with appropriate parameter mapping. I don't see any methods inside your interface.
Please checkout the this link as well as the link mentioned above by #Perception
If there are no Java classes or Java source hidden inside this DLL (which would be ... strange), then it will never work this way. You can't instantiate C# classes or use C# interfaces. MessageBox.Show( isn't Java either, it is Windows Forms code.

Scala+Android+Roboguice: ClassNotFoundException in loader

I'm evaluating Scala on Android by starting with the NotesList demo. I was able to replace the NotesLiveFolder.java file with its Scala equivalent without problem.
Next, I introduced Roboguice, creating a simple NotesListApplication.java that sets up the Guice modules, and successfully injected a resource into the NoteEditor.java activity.
Finally, I when I tried to replace NotesListApplication.java with its Scala equivalent, I get the following runtime error before the application finishes booting:
java.lang.ClassNotFoundException: com.example.android.notepad.NotesListApplication in loader dalvik.system.PathClassLoader[/data/app/com.example.android.notepad-1.apk]
I created a Google Code project containing the complete Eclipse project and source. The original functioning NotesListApplication.java is:
package com.example.android.notepad;
import java.util.List;
import roboguice.application.RoboApplication;
import com.google.inject.Module;
public class NotesListApplication extends RoboApplication {
private Module module = new BindEverything();
public void setModule(Module module) {
this.module = module;
}
#Override
protected void addApplicationModules(List<Module> modules) {
modules.add(module);
}
}
and the Scala equivalent that causes the error is:
package com.example.android.notepad
import roboguice.application.RoboApplication
class NotesListApplication extends RoboApplication {
val module : Module = new BindEverything()
override protected def addApplicationModules(modules:java.util.List[Module] ) {
modules.add(module)
}
}
I'm building in Eclipse with the ScalaIDE plugin. I'm not running any treeshaker/proguard/etc.
The disassembly shows the Scala classes as expected:
Class descriptor : 'Lcom/example/android/notepad/NotesLiveFolder;'
...
Class descriptor : 'Lcom/example/android/notepad/NotesListApplication;'
Any ideas what could cause this?
Upgrade to 2.0-SNAPSHOT of RoboGuice and then you dont have to use RoboApplication and it all binds automatically. For more how to bind check out the slides from Mike Burtons presentations about RoboGuice at AnDevCon 2 and check out the 2.0 section on the wiki.
Like I posted on the mailing list maybe check out the apk with dedexer and see if the class was actually removed e.g. by Proguard or renamed so it cant be found as a next step.

Categories

Resources