I downloaded and imported xalan-2.5.0.jar to my netbeans project in order to use the CAlloc.class function. But i cant figure out how to use the CAlloc function.
i imported the package by doing this,
import JLex.*;
i wanted to import specifically the calloc class but i get error when i tried this
import JLex.CAlloc;
the error says "CAlloc is not public in JLex; cannot be accessed from outside package" , i opened and checked the CAlloc.class and it not public but i cant edit it, may be if there is a way to edit the class ???
Related
In an Android studio library project, the following code piece gives error.
package my.package.a;
import my.package.b.Test; //this shows unused, why??
public class **Test** extends my.package.b.Test { //"Test is already defined in this compilation unit." why?
...
}
extends my.package.b.Test this line is using package b, isn't it? so why the import statement shows unused?
These two Test classes are in different packages, why does it have name conflicts??
Solution:
Refer to full name and delete import statement.
Cannot import my.package.b.Test as it's in conflict with current class name.
The import is not needed here because you're already calling out my.package.b.Test by full name. If you use the fully qualified reference to a symbol, there is no need to import it.
I'm new in java, please help me to understand this.
I can see there is ReadHtml class and defined with one public method. But when i put this code in ecplise, it shows red mark under WebClient with tag that "this cannot resolved to a type". May I know what does it mean? Gone through all about method definition but couldn't find any remedy to understand this.
Can I get any help ?
public class ReadHtml {
public static LinkedList<String> readJacksonCounty(String urlName, String pStartDate,String pFinishDate)
{
LinkedList<String> xmlListReturn=new LinkedList<String>();
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "error");
final WebClient webClient1 = new WebClient(BrowserVersion.CHROME);
webClient1.setJavaScriptTimeout(60000);
webClient1.getCookieManager().setCookiesEnabled(true);//enable cookies
webClient1.getCache().clear();
You are missing an import of this library:
import com.gargoylesoftware.htmlunit.WebClient;
Add this to the top of your file (and read dsp_user's comment for future reference).
Basically "...cannot be resolved to a type" means that type is not available on the class path. If you're just using eclipse refere to How to import a jar in Eclipse.
If you already added the needed jar onto your class path, you are missing the import statement. Imports just make it so that you dont have to use a class's fully qualified name. (you can type
MyClass myClass;
as opposed to
com.some.package.MyClass myClass;
if you add
import com.some.package.MyClass;
at the top of your file.
Note that if you want to build a jar from your project you'll need some kind of build tool. If you choose to use Maven, which is very common, just read any tutorial on how to get started and manage dependencies.
This might be a duplicate, but I cannot find an answer using the below answers and many other sites on the internet...
My conundrum:
I am attempting to (poorly) run some classes from a jar in jsp. Effectively what I have is the following:
<%#page import="edu.cs242.hadoop.*" %>
<%
... do some stuff ...
MRSearcher ss = new MRSearcher();
... do some stuff ...
%>
But every time I try to run the jsp I get the following error:
An error occurred at line: 32 in the jsp file: /hadoop.jsp
MRSearcher cannot be resolved to a type
My webapp structure looks like:
/
|hadoop.jsp
|lucene.jsp
|index.jsp
|WEB-INF/
|lib/
|lucene.jar
|hadoop.jar
|classes/
|*.java for our hadoop.jar
I've tried calling the jar itself and compiling the java through tomcat, both produce the same results.
Here is a snippet from our MRSearcher class:
package edu.cs242.hadoop;
import java.io.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
/**
* Created by cloudera on 3/10/14.
*/
public class MRSearcher {
MRSearcher() {}
public String[] run(String arg1, String arg2) {
String[] things = new String[] {};
// do stuff
return things;
}
}
There are other classes, but this one is the one that allows us to interface with the rest of the program. The main is in a file called: Main.java, and it does nothing but runs this for command line output. The syntax is correct as we can run the main and retrieve output.
I don't mean to sound insolent, but please don't comment on the futility and awfulness of including things like JAR files in JSP. This is never going to production, it's a school project that doesn't need the necessity of correctness, it needs the necessity of functioning. If I were doing this for a job I would do it right, but right now I don't care about learning about the correct way to separate logic and presentation layers in JSP -- I can do that just fine in other languages and understand the concept very well.
I have looked through and attempted to use the following solutions before posting this, all of this has failed:
how to run jar file methods in jsp
How to call method from jar file in JSP?
how to reference an external jar in jsp app?
And more to try to solve this problem.
In WEB-INF/classes/ you must have MRSearcher.class file. Keep in mind JSP files are compiled first time you access it, so your project can compile although your JSP are not well.
On the other hand, your MRSearcher() constructor must be public, if you omitte this, by default the constructor will be package and cannot be accessed from other packages. Check if your Main.java class is in same package of MRSearcher. If yes, this is why it can invoke MRSearcher constructor.
I hope this helps you.
Regards,
Hi I had a program which worked fine in a .jar file.
Basically all the classes were part of the same package called : "eu.floraresearch.lablib.gui.checkboxtree"
They ALL are located in the SAME "checkboxTree" folder. Each file has a line stating
package eu.floraresearch.lablib.gui.checkboxtree;
I need to modify the code and to integrate it in another project.
So I took all the .java files, copied them in my Eclipse project folder (no package anymore), and got rid of the "package eu.floraresearch.lablib.gui.checkboxtree;" line in each files. Everything is fine except for one file comprising an enumeration.
Originally the file looked like this:
package eu.floraresearch.lablib.gui.checkboxtree;
public class QuadristateButtonModel extends DefaultButtonModel {
public enum State {
CHECKED, GREY_CHECKED, GREY_UNCHECKED, UNCHECKED
}
...
}
The problem is, there is another class which originally imported the above class enumeration:
import eu.floraresearch.lablib.gui.checkboxtree.QuadristateButtonModel.State;
public class QuadristateCheckbox extends JCheckBox {
public QuadristateCheckbox() {
this(null);
}
public QuadristateCheckbox(String text) {
this(text, State.UNCHECKED);
}
...
}
First of all I find it weird how enumerations can be imported.. But it worked fine when everything was inside the package.
Since all my .java files are in the same folder now, I just removed the package line.
However I have this issue with the QuadristateCheckbox class which imports "QuadristateButtonModel.State".
If I change the import line with
import QuadristateButtonModel.State;
it states
The import QuadristateButtonModel cannot be resolved
I tried various things I found on the internet like
import static QuadristateButtonModel.State.*;
or
import QuadristateButtonModel.State.*;
but the same error messages occur:
The import QuadristateButtonModel cannot be resolved
On top of that, in the above code from QuadristateCheckbox class:
public QuadristateCheckbox(String text) {
this(text, State.UNCHECKED);
}
an error message
State cannot be resolved to a variable
which is understandable given the fact that I fail to import the State enumeration.
What can I do? Please explain to me what is wrong
PS: The code was taken from this site: http://www.javaworld.com/article/2077762/core-java/swing-based-tree-layouts-with-checkboxtree.html
The authors provide classes to build checkable trees.
I am trying to implement JUnit unit testing using a ServletUnit to test a servlet, specifically a java file named SignedNotesServlet.java . This test class is in the same directory as SignedNotesServlet.java . I am using Eclipse.
However, I am having trouble writing the correct syntax for registerServlet method that is part of ServletUnit and HttpUnit. I have not yet run the program. The errors I am receiving are
Syntax error on tokens, FormalParameter expected instead
Syntax error on token "class", identifier expected
Syntax error on token(s), misplaced construct(s)
Syntax error on token ""SignedNotesServlet"", invalid FormalParameterList
Here is my code:
package notetaker;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.fail;
public class SignedNotesServletTest {
ServletRunner sr = new ServletRunner();
sr.registerServlet( "SignedNotesServlet", SignedNotesServlet.class.getName() );
private SignedNotesServlet signednotes;
#Test
public void test() {
fail("Not yet implemented");
}
}
I think I correctly added the jar file the buildpath, using instructions from http://tinyurl.com/ku7huss . I used http://tinyurl.com/b55fn as my main reference but am also looking at the few registerServlet examples on the web (I can't post those links for reference since I need a 10 reputation to post more than 2 links). I am not entirely sure what could be wrong since I basically copy-pasted from the second website and made (what I thought) were appropriate changes.
I also thought that maybe something was wrong with "SignedNotesServlet" since there were quadruple quotes in the error, and I removed them, but it still doesn't work out, and I don't think that would have been correct syntax anyway, based on the examples.
This is the problem:
sr.registerServlet( "SignedNotesServlet", SignedNotesServlet.class.getName() );
This statement isn't in a method or constructor - it needs to be. Either put it within the test itself or put it in a setup method. If you put that code into the individual test, I'd also recommend making sr a local variable for that test. If you put it into a setup method, you'd need sr to be an instance variable still, but I'd suggest making it private and giving it a more useful name.
I am not entirely sure what could be wrong since I basically copy-pasted from the second website
But you copied it into an inappropriate place. Note that this has nothing to do with servlets, JUnit, ServletUnit or your build path - it's simply invalid Java.