JSP could not find available java class - java

I used following code to call the java class from the JSP page.
<%String something=com.Package1.PrintInPicture.workingFunction(recentData);%>
I have package named as "com.Package1" as well as class and method named as "PrintInPicture" and "workingFunction(Stirng data)" respectively in that package. This is shown in code below:
package com.package1;
public class PrintInPicture {
static int width, height;
public static String workingFunction(String img_name) throws IOException{
}
But my JSP page is showing following error in the code which I have shown above:
cannot find symbol
symbol: class PrintInPicture
location: package com.Package1
Please, Help me to solve this error.

Related

Java 11 compiler returns "package does not exist"

I am trying to re-learn some programming skills.
I have decided to use an old favourite - Logic Gates Simulation - as a learning tool.
I want to set this project up to use packages.
My CLASSPATH is "C:\Users\ruthm\Documents\java"
My project code is in the directory:
C:\Users\ruthm\Documents\java\logic
I am using Java 11
My classes so far are Connector.java and ConnectorTest.java
the code for Connector is as follows:
package logic;
/*
Class Connector
A connector forms the input and output of a LogicGate.
The connector "output" object of a gate can be passed to another gate to form the input.
*/
public class Connector{
private int value;
public Connector(){
value=0;
}
public Connector(int state){
value=state;
}
public void setValue(int state){
value=state;
}
public int getValue(){
return value;
}
}
The code for Connector Test is as follows:
/* Test Case for Connector */
import logic.*;
class ConnectorTest{
public static void main (String[] args){
logic.Connector myConnector = new logic.Connector();
System.out.println("initial value: "+myConnector.getValue());
myConnector.setValue(1);
System.out.println("Set value: "+myConnector.getValue());
}
}
Connector.java compiles without error.
When I try to compile ConnectorTest.java I get the following from the compiler:
C:\Users\ruthm\Documents\java\logic>javac ConnectorTest.java
ConnectorTest.java:4: error: package logic does not exist
import logic.*;
^
ConnectorTest.java:9: error: package logic does not exist
logic.Connector myConnector = new logic.Connector();
^
ConnectorTest.java:9: error: package logic does not exist
logic.Connector myConnector = new logic.Connector();
^
3 errors
C:\Users\ruthm\Documents\java\logic>
I have been following guides on directory structure and packages to try and solve this but I am clearly not understanding something.
I get the same errors if I declare ConnectorTest to be in package logic as well.
Can someone handhold me and show me where I am going wrong?
My project code is in the directory:
C:\Users\ruthm\Documents\java\logic
This means that to avoid trouble, you'd be better off using same package directive to them both.
So if you add this:
package logic;
to your ConnectorTest class, it should be ok, given you don't have any other issues.
If you want to keep your ConnectorTest class in default package, you could move your ConnectorTest.java file to C:\Users\ruthm\Documents\java directory, but keep your Connector class in the logic directory.

How to reference a class in a different package in the same project

I've tried working through some similar questions but I'm not getting anywhere
I have a main class in a package called overview.
In that class I create a string
I then want to send the string to another class in a different package in the same project
In my main class I have:
package Overview
import Bravo.*;
//some code
String s;
///Some code
Bravo.mane(s)
In the recipient class I have
package Bravo;
public class mane {
public mane(String s) {
// TODO Auto-generated constructor stub
}
}
When I am in the sending class main I seem to be able to access the class (in that when I type Bravo. (it gives me the class available in that package) but I still get an error saying that Bravo cannot be resolved ( in main).
Bravo.mane(s)
this is the place you are getting the error , you are calling the constructor of the class. you can't call the constructor. constructor will be invoked when you instantiate the object.
ex:-
mane maneObj = new mane("string");

Inner Nested Static Class cannot be called from another class

I have one class in a file named WeatherContract.java which has a static inner class, as follows:
public class WeatherContract {
...
...
public static final class WeatherEntry implements BaseColumns {
...
...
}
}
Now I am trying to call the inner class in another file called TestWeatherContract.java as follows
...
import com.example.android.sunshine.app.data.WeatherContract;
...
public class TestWeatherContract extends AndroidTestCase {
...
public void testBuildWeatherLocation() {
Uri locationUri = WeatherContract.WeatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);
...
Now in the following line, the word "WeatherEntry" is marked in red and when I hover on the word I get the following error "Cannot resolve symbol 'WeatherEntry'.
Uri locationUri = WeatherContract.WeatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);
Please note that I am not getting any error in the import statement, so I'm assuming that there are no errors in stating the path of the class.
Also, I have another file called FetchWeatherTask.java. I have the following import statement at the beginning of the file:
import com.example.android.sunshine.app.data.WeatherContract.WeatherEntry;
In this case, in the import statement again the word "WeatherEntry" is marked in red and I get the error "Cannot resolve symbol 'WeatherEntry'".
Please help. I'm on Android Studio 1.5. I have posted this question earlier, but it was put on hold because I provided incomplete details. So I am posting it again with all details. I'm sorry if I have violated the rules of the community, I am new here. Thank you.
WeatherEntry is a class and not a member. To access methods of WeatherEntry you still need an instance of it. E.g.
WeatherContract.WeatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);
should be
WeatherEntry weatherEntry = new WeatherContract.WeatherEntry();
weatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);

Netbeans doesnt recognize class in the same package

i am creating a little game with libgdx framework and netbeans 8. I have all java classes in a single package that match with the directory structure.
The problem is that i cant import or isntantiate classes, for example:
package com.myfolder.folder2;
import ...
public class myclass1{
private myclass2 mc2;
etc...
}
In this case myclass2 is public and is inside the package but netbeans complains "cannot find symbol".
If i try with alt+enter, netbeans says "Create class myclass2 in package com.myfolder.folder2" or the same like an inner class. If i press the first option, netbeans create a class in the package with the file name myclass2_1 (becouse myclass2 exists!), and myclass1 doesnt recognize the new class.
If i try to import the class:
import com.myfolder.folder2.myclass2;
It gives me the same error, and in fact the code completion tool only gives me one crazy option in the import sentence:
import com.myfolder.folder2.myclass1;
Import the same class.
What can i do? I never have these problems using netbeans.
PD: Sorry for my english :)
You can use a class inside the same package like this:
ClassName classVariableName = new ClassName();
Then when you want to run something from the class you would put
classVariableName.MethodThatIWantToRun();
Or if you want to access a property from that method you would access it in a very similar way:
classVarabileName.PropertyIWantToAccess
Example:
You have one class with a property you want to access:
class MyClass {
public int MyProperty = 5;
}
You access it in this class:
public class MainClass {
public static void main(String[] args) {
MyClass myClass = new MyClass();
System.out.println(myClass.MyProperty);
}
}
If that doesn't work than you might have some other problem.
It was an error with one of my class package definition:
public class DesktopLauncher{
public static void main(String... args){
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
.
.
.
new LwjglApplication(new MyClass, config);
}
}
It was in MyClass, becouse i copied a snippet from an older project, and accidentally copied the older package.
NetBeans is not smart enough,
Solution: just declare the package name in all classes, example:
Class A:
package test;
public class ClassA {
public static void main(String[ ] args) {
ClassB.myFunctionB();
}
}
Class B:
package test;
public class ClassB {
public static void myFunctionB () {
System.out.print("I am ClassB!");
}
}

How to consider maven dependency in java program compilation via command line

I executed my java file like this:
javac -cp ".:/root/Desktop/karim/software/UIMA/yagogit/yodaqa/gradle/wrapper/gradle-wrapper.jar" LATByFocus.java
which gives error like:
LATByFocus.java:5: package org.apache.uima does not exist
import org.apache.uima.UimaContext;
^
LATByFocus.java:6: package org.apache.uima.analysis_engine does not exist
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
^
LATByFocus.java:7: package org.apache.uima.fit.component does not exist
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
^
LATByFocus.java:8: package org.apache.uima.fit.util does not exist
import org.apache.uima.fit.util.JCasUtil;
^
....
LATByFocus.java:36: cannot find symbol
symbol: class JCasAnnotator_ImplBase
public class LATByFocus extends JCasAnnotator_ImplBase {
^
LATByFocus.java:37: cannot find symbol
symbol : class Logger
location: class cz.brmlab.yodaqa.analysis.question.LATByFocus
final Logger logger = LoggerFactory.getLogger(LATByFocus.class);
^
LATByFocus.java:39: cannot find symbol
symbol : class UimaContext
location: class cz.brmlab.yodaqa.analysis.question.LATByFocus
public void initialize(UimaContext aContext) throws ResourceInitializationException {
^
LATByFocus.java:39: cannot find symbol
symbol : class ResourceInitializationException
......
So I wanted to try considering pom.xml along with jar file in command line - pom.xml
Is it possible?
I am trying to execute these files https://github.com/brmson/yodaqa/tree/master/src/main/java/cz/brmlab/yodaqa/analysis/question
in project : yodaqan

Categories

Resources