Eclipse Java is finding "cannot be resolved" errors in comments? - java

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.

Related

Missing class from package within Netbeans when using Spire.Doc.jar for docx files

I downloaded and installed the free Spire.Doc.jar file to work with .docx files. When I run it within Netbeans the functionality works fine however when I attempt to build the program I am getting the following error:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' less than -source '1.8'
Note: Creating static metadata factory ...
error: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1
not found
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1 not found
I have added the .jar file to my class path however there appears to be a class file missing from the com.spire.packages location.
Does anyone know if this is a Netbeans issue or does it look like there is an issue with the .jar file? I find it strange that it works when I run it within Netbeans but the above error occurs when I attempt to build the project.
I managed to get my application to build. What I had to do was remove the following code from my class and then it worked:
document.getMailMerge().MergeImageField = new MergeImageFieldEventHandler()
{
#Override
public void invoke(Object sender, MergeImageFieldEventArgs args)
{
mailMerge_MergeImageField(sender, args);
}
};
private static void mailMerge_MergeImageField(Object sender, MergeImageFieldEventArgs field)
{
String filePath = field.getImageFileName();
if (filePath != null && !"".equals(filePath))
{
try
{
field.setImage(filePath);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I'm not sure why it didn't work with this included however I got this code from the following website:
https://www.c-sharpcorner.com/article/how-to-perform-mail-merge-in-word-document-in-java/
therefore I will inform them in case this happens to someone else in the future.

Netbeans - a method call becomes italic - and causing error

What does it mean in netbeans when a statement like the code below becomes all italic?
MessageBox.show("test", "test");
I get the error below as well on runtime. But not when coding, just the ".show()" method that's not appearing in autocomplete. But the class is already in its appropriate folder and is already imported. What could be the problem here as well?
Uncompilable source code - Erroneous sym type: library.MessageBox.show
Complete code:
public class MessageBox {
public static void show(String titleString, String messageString)
{
JOptionPane.showMessageDialog(null, messageString, titleString, JOptionPane.INFORMATION_MESSAGE);
}
}
The above code you provided runs fine on eclipse.
As you said you are using Netbeans and may be affected by a bug. Try this:
Open the project properties, select the Build-Compiling, uncheck
"Compile on save" and rerun the application.
This will make sure all your source code becomes recompiled before running it.
Ref: https://netbeans.org/community/news/show/1647.html

Why Unity3d failed importing jar plugin?

I have a small Unity3d project to integrate JAR with it. My (simplified) java class in Android Studio library project is like below code:
package com.playsqreen.library.api;
... imports ...
public class PlaysreenAPI {
private static PlayscreenAPI _api;
private PlayscreenAPI(Activity activity) {
this.activity = activity;
}
// static method to create singleton
public static PlayscreenAPI build(Activity activity, String key) {
if (_api == null) {
// post processing something
// before returning instance of this class
_api = new PlayscreenAPI(activity);
}
return _api;
}
public String doEchoThis(String msg) {
return "ECHO: " + msg;
}
}
So from Android Studio, I generate my JAR and dump it into ../MyProject/Assets/Plugins/Android and from Unity IDE I can see something like below:
Then I create a C# script like below to load my java class:
void Start () {
_builder = new StringBuilder();
try
{
_builder.Append(">>> Step 1\n");
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
if (activityClass != null)
{
_builder.Append(">>> Step 2\n");
AndroidJavaObject activity = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
if (activity != null)
{
_builder.Append(">>> Step 3\n");
AndroidJavaClass apiClass = new AndroidJavaClass("com.playsqreen.library.api.PlayscreenAPI");
if (apiClass != null)
{
_builder.Append(">>> Step 4\n");
object[] args = { activity, secretKey };
api = apiClass.CallStatic<AndroidJavaObject>("build", args);
}
}
}
}
catch (System.Exception e)
{
_builder.Append(e.StackTrace.ToString());
}
}
I print my StringBuilder in Text UI object in order for me to capture on which Step my code brakes, and it turns out after step 3. and my Text UI object prints:
java.lang.ClassNotFoundException:com.playsqreen.library.api.PlayscreenAPI and etc...
A thread I found here suggest me to use Java Decompiler to check if the java class really included in the Jar, from this site. And so I did, and the Java Decompiler shows my java class does exists (see below)
So I really stuck now. How can I load my java class from Unity? Please help.
Thanks.
After following lysergic-acid advice below, I includes the rest of jars that required by my custom jar, see below pic. And everything fine :)
You did not post the full error message you are getting at runtime. Also you did not mention which of your debug prints get printed, so i'll try to come up with a few different issues that you can check. Hopefully, one of these can assist in fixing the issue:
JAR name contains '.' (period character). Not sure how Unity interprets this (i've never used such a naming convention myself). Select the .JAR file in Unity and make sure that Unity marks it up as an Android plugin (should have "Android" selected in the plugin importer. I would also try to rename that to a name without any periods just to be on the safe side.
Wrong invocation of the Java method: in your example, the static method build in Java receives a single argument (Activity), but when you're calling it from Unity, you're passing an array of 2 arguments.
Missing dependencies: When your native Java code relies on other classes (e.g: from other libraries), in case you do not include these libraries with your .JAR file, your class will not be loaded at runtime and it will fail with cryptic errors such as NoClassDefFoundException. Make sure to include all dependencies as well.
**Shameless Promotion: ** I offer services to fix Android related issues in Unity. Check it out here, in case you're interested :)
Install newest JDK version and try again.

Eclipse doesn't recognize jar method

I am struggling with a very strange issue (eclipse mars.1)
I have a jar which I am using its methods.
I have added a new method to the class I use, created a new jar, refreshed the client project, I CAN SEE the new methods in the client project explorer, but I cannot use them in the client code!!! I can use only the old methods! It is making me crazy!!
Please see image:
In case image was not uploaded, the error message I get is: "The method initLog(String) is undefined for the type Log4jWrapper"
public void init(String a_strPropertiesPath){
Log4jWrapper.initLog("aaa"); //doesn't recognize initLog
}
public void log(LogLevelEnum a_level, String a_sMethodName, String a_sMessage){
Log4jWrapper.writeLog(a_level, a_sMessage); //recognizes writeLog
}
Thank you all!
You have multiple imports of the same jar in your classpath :-)

method deleteQuietly(File) undefined for type FileUtils

I am studying a code already written, but there are still some mistake when I compile it with Eclipse on my computer.
One of those error is for the following method, and other ones also
private static void deleteFile(File baseDir, String name) {
File file = new File(baseDir, name);
if (file.exists()){
FileUtils.deleteQuietly(file);
}
}
I have added the jar org.apache.commons.io.FileUtils to my buildpath and imported it in my class so I don't think it is coming from there, but I don't know why it is not working. I've checked and deleteQuietly is indeed a method from the class FileUtils. Help me please
Thank you
The method deleteQuietly(File file) is defined since version 1.4.
Check the version of Apache Commons that you imported.

Categories