I was running a Java code online, but there is an error for the java code. The error line is:
package binary.ga;
The error information for this line is "the declared package "binary.ga" does not match the expected package". Can anybody help me fix the problem?
Normally that means that the .java file is not in the correct folder. Your folder structure should look like:
binary/
ga/
MyClass.java
You just have to replace this line with correct package, for example my project structure looks like this:
so package for Content class is net.elenx
Related
I have a package called org.mine.level1.level2
I want to add a package called org.mine.helper with a class called org.mine.helper.Calc
So I went to java/org/mine where the directory 'level1' already is and created 'helper'. Then I created Calc.java and put a class in it. I also added usage of the class to org.mine.level1.level2 code (a couple of java files in there).
When javac compiled the modified level2 code it said that the org.mine.helper.Calc file didn't exist.
I looked at the existing tree and there was a build.xml file which said
<property name="src" location="java" />
which is the parent of the org directory. So it seemed like whatever is reading build.xml doesn't need to know the names of all the java files. That indicated to me I could add a directory at will and it would just be incorporated.
In tutorials that have multiple packages they always run javac on each file, cause the class files to go in some directory and put that in a class path. I guessed that build.xml is defining all that and I could just add my stuff.
What can I do to get my new java code compiled for the benefit of the places I use it?
Error messages:
org/mine/level1/level2/Usage.java:8: error: package org.mine.helper does not exist
import org.mine.helper.Calc;
^
org/mine/level1/level2/Usage.java:74: error: package org.mine.helper does not exist
org.mine.helper.Calc.compute();
You said:
So I went to java/org/mine where the directory 'level1' already is and created 'helper'. Then I created Calc.java and put a class in it.
But if you wanted to add a source file to the package org.mine.helper, then you should have gone to org/mine/helper, and created Calc.java there. So, you should either make this change, or, if you want to refer to the Calc class as it currently is located, then use this import statement:
import org.mine.helper.level1.Calc;
I have a Stack.java file stored in
C:\Users\Aaditya\Documents\Github\Data Structures\com\stack\Stack.java
In the declaration of the file, I have given this
package com.stack;
So, now I have a Parantheses.java file stored in
C:\Users\Aaditya\Documents\Github\Data Structures\Parantheses\Parantheses.java
And now when I have the below code in this file, and subsequently I compile it,
import com.stack.*;
I get the following error
C:\Users\Aaditya\Documents\GitHub\Data Structures\Parantheses>javac *.java
Parantheses.java:1: error: package com.stack does not exist
import com.stack.*;
^
Can anyone sort this error out for me.
PS:
When I put all the java files in one folder and then compile them (without the 'import' and 'package' thing), I dont get any error. Program runs succesfully.
Thanks. :)
Try using -sourcepath while using javac which will allow you to include files from different location.
Links :
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html#CBHHCGFB
On the other hand better way to manage dependencies is maven.
I'm trying to build my first Pig UDF in Java and am having trouble calling the function when building with Eclipse (I have the pig 0.10.0 jar file in my class path). The source file is in /com/foo/bar/pig/IsInternal.java and the class file is placed in /bin/com/foo/bar/pig/IsInternal.class by Eclipse.
My code looks like this:
package com.foo.bar.pig;
// ... imports ...
public class IsInternal extends FilterFunc {
public Boolean exec(Tuple input) throws IOException {
// ... code here ...
return true; // or false
}
}
After I compile it, I run jar -cf PiggyBank.jar BiggyBank from just outside the project directory to package it all up into a JAR. When I run Pig, I try the following in the grunt shell:
REGISTER /full/path/to/PiggyBank.jar
DEFINE isInternal com.foo.bar.pig.IsInternal();
A = LOAD '/some/file/in/hdfs' USING PigStorage();
B = FILTER A BY isInternal($1);
At that point I get the following error:
ERROR 1070: Could not resolve com.foo.bar.pig.IsInternal using imports: [, org.apache.pig.builtin, org.apache.pig.impl.builtin.]
The Java code itself is fine (I've tested it), and I've tried playing around with different class paths in the DEFINE without any luck. I haven't found anything of help online. How would I fix this?
I'm a little queasy about the packaging into a .jar by hand. Can you try putting into an eclipse project and exporting from there?
Also, can you confirm the directory structure of the jar? It should be like this: PiggyBank.jar/com/foo/bar/pig/IsInternal.class
This error look like you not fix the class path path error for your UDF i was also have the same problem you in this link i explain how to fix above error . Hope it will help you .
This must be a super overasked question. Although here goes:
I have a java file for testing around (hworld.java) and am trying to import conio.jar, a JAR which is a wrapper of Conio. The JAR contains only one class file (conio.class) and META-INF. Trying to do import conio.* or import conio.conio shows me this:
C:\Documents and Settings\Nick\Desktop>javac -cp *.jar; hworld.java
hworld.java:3: error: package conio does not exist
import conio.*;
^
1 error
And compiling it like javac -cp conio.jar hworld.java still errors out while compiling. I even extracted the jar and had conio.class in the same directory as hworld.java but to no avail. The JAR is in the same directory as hworld.java, as well.
Anyone have any idea on how to fix this?
You don't mention whether conio.class is defined in package conio. If it is not, then simply use the class without importing it. Remove the import.
It's actually not possible. You need to put the other class in a package if you want to import it.
What's the syntax to import a class in a default package in Java?
Find out what package Conio is in - an easy way to do this is to open the jar as a zip file, the package will correspond with the folder structure of the archive. For example if Conio is in x/y/z then import x.y.z.Conio and compile/run with conio.jar on the classmate.
Im recieving the title error on several lines I used a example to create a application I did create a folder for .com.example.. and placed it in the root directory but it did not work I tried editing the Java script manually and it also did not work..
From what I can tell, it sounds like the top of your class with the compile error you mentioned has a package declaration like the following:
package com.example.android.softkeyboard;
However, the package that actually contains the class is as follows:
your.test.com.example.android.softkeyboard
You need to either change the package declaration line to look like the package directory structure or change the name of the package to look like the package declaration in the code. The latter option would be better because I suspect you've probably copied code from somewhere into your own package and that's why things aren't compiling. If you start renaming packages, you may cause more compile errors to appear before getting everything fixed. If you're new to Java, this can be very confusing to deal with.
If you are completely unfamiliar with how packages work, or if you'd like to read up on it, here are some good resources:
Oracle Java Package Tutorial
Wikipedia Java Package Article