I have these two java files: Xls_Reader.java and WriteXMLFile.java in the same directory called filegeneration. I am trying to use Xls_Reader class in WriteXMLFile.java so I did this
package fileGeneration;
import fileGeneration.Xls_Reader;
However I keep getting this error when trying to compile
WriteXMLFile.java:27: error: cannot find symbol
import fileGeneration.Xls_Reader;
symbol: class Xls_Reader
location: class WriteXMLFile
WriteXMLFile.java:65: error: cannot find symbol
Xls_Reader xlsDataSheet = new Xls_Reader(dataSheetPath);
Why is Xls_Reader not being found?
Update: the following is in Xls_Reader
package fileGeneration;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
//import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Xls_Reader {
In order to let the compiler knows about the classes to be compiled, you need to specify the classes explicitly. The compiler won't use the same folder to know that. You can read more about how ClassPath works here (https://docs.oracle.com/javase/tutorial/essential/environment/paths.html)
An example of compiling multiple files from the command line here:
https://www.baeldung.com/java-compile-multiple-files
I see that you are using another libraries like Apache POI, therefore it would be more convenient to use Maven or Gradle to handle both dependencies and deployments.
Related
Im trying to write a program that will read an xml file and print to itext.
However, I getting a class conflict in import statements. I dont know how to resolve this issue.
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.w3c.dom.NodeList;
import org.w3c.dom.*;
import com.itextpdf.text.Annotation;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfAction;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
The "Document" and "Element" classes between dom4j and itext are conflicting.
Does anyone know a workaround? Is there any eclipse magic I can do?
The workaround here is to only import one of the two (or many) conflicting classes. Then use the fully qualified class name for the class not imported. For example:
import org.dom4j.Document;
// import com.itextpdf.text.Document; <-- don't import this
Then when using the itext class, refer to it as:
com.itextpdf.text.Document doc;
I would recommed importing the class/package of classes which you use the most in your Java file. This would let you avoid having to type a fully qualified class name as much as possible.
In such cases , you should use fully qualified class name for one of the conflicting classes while using it.
You need to specify the package when using them in your code.
Otherwise there is an ambiguity as Document could refer to either org.dom4j.Document or com.itextpdf.text.Document and Element could refer to org.dom4j.Element or com.itextpdf.text.Element.
Import statements in Java act like aliases for fully qualified type names. Trying to use the same alias for two or more types won't work because of ambiguity.
Therefore do either not use import statements for any of those conflicting types and use their fully qualified names (package plus type name) or import at most one of those types only.
I got some source code for an Entertainment Game Bot (for Runescape) years ago and am trying to run it now. However, a lot of the imports are unrecognized by jGrasp and I don't know how to fix the code as I am still only a student. The code for the imports is below:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Map;
import org.rsbot.bot.Bot;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.script.util.*;
import org.rsbot.script.*;
import org.rsbot.script.wrappers.*;
import java.util.Random;
import javax.swing.JOptionPane;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Game;
import org.rsbot.util.GlobalConfiguration;
#ScriptManifest(authors = { "Enfilade" }, keywords = {"rune", "riot"}, name = "Rune Riot", version = 1.0)
The program code is not shown as it is far over the character limit of this post. When I attempt to compile the code it gets a lot of import-related errors such as:
RuneRiot.java:17: error: package org.rsbot.bot does not exist
import org.rsbot.bot.Bot;
Please tell me what I need to do to solve the import errors and get the code to run properly. Thanks!
package org.rsbot.bot does not exist means that you are missing your org.rsbot.bot package.
This can mean one of two things:
You don't have the package. Solution: get the package.
You haven't added the package correctly. You need to get your jGrasp to put the Jar or source files (whatever format they are in) for the missing packages on your build path.
I have a project using liquibase-core 2.0.3. When I updated to liquibase-core 3.3.0 I'm getting a lot of compiler class not found errors for the classes below.
Any help on info on where/what they have been replaced with is much appreciated?
import liquibase.change.core.AnonymousChange;
import liquibase.database.core.MaxDBDatabase;
import liquibase.database.typeconversion.TypeConverter;
import liquibase.database.typeconversion.core.CacheTypeConverter;
import liquibase.database.typeconversion.core.DB2TypeConverter;
import liquibase.database.typeconversion.core.DefaultTypeConverter;
import liquibase.database.typeconversion.core.DerbyTypeConverter;
import liquibase.database.typeconversion.core.FirebirdTypeConverter;
import liquibase.database.typeconversion.core.H2TypeConverter;
import liquibase.database.typeconversion.core.HsqlTypeConverter;
import liquibase.database.typeconversion.core.InformixTypeConverter;
import liquibase.database.typeconversion.core.MSSQLTypeConverter;
import liquibase.database.typeconversion.core.MaxDBTypeConverter;
import liquibase.database.typeconversion.core.MySQLTypeConverter;
import liquibase.database.typeconversion.core.OracleTypeConverter;
import liquibase.database.typeconversion.core.Postgres83TypeConverter;
import liquibase.database.typeconversion.core.PostgresTypeConverter;
import liquibase.database.typeconversion.core.SQLiteTypeConverter;
import liquibase.database.typeconversion.core.SybaseASATypeConverter;
import liquibase.database.typeconversion.core.SybaseTypeConverter;
import liquibase.snapshot.jvm.DB2DatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.DerbyDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.H2DatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.HsqlDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.InformixDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.MSSQLDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.MySQLDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.OracleDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.PostgresDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.SQLiteDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.StandardJdbcDatabaseSnapshotGenerator;
MaxDBDatabase was pulled into a separate extension https://github.com/liquibase/liquibase-maxdb so you will need to include that jar as well.
The TypeConverter code mainly moved to the classes in liquibase.datatype.
The database-specific SnapshotGenerator classes were replaced with a more general-purpose SnapshotGeneratorFactory and object-specific subclasses vs. database-specific subclasses.
I see you cross-posted to the liquibase forum at http://forum.liquibase.org/topic/replacement-for-missing-liquibase-classes-moving-from-liquibase-2-0-3-to-3-3-0#49382000001219004 If you have specific usage questions, that is probably the best place to follow up since it is more discussion-oriented than stackoverflow.
I have a package named utilities which has several sub-packages. The utilities package has no classes by itself but the sub-packages do.
I can import all the classes from the sub-packages one by one by doing this:
import utilities.consoleredirect.MessageConsole;
import utilities.generalutils.Helper;
import utilities.generalutils.Pair;
import utilities.generalutils.PropertiesUtils;
import utilities.sqlhandling.Connector;
import utilities.sqlhandling.SQLDatabase;
import utilities.sqlhandling.User;
import utilities.tweetshandling.TwitterTools;
import utilities.tweetshandling.WordCounting;
But if I try to do import utilities.*; I get the error that the package does not exist (in my IDE - NetBeans) but if I try to create the package then I get the error that the file already exists. The folder structure is correct, this is it for easier visualization:
So why can't I just do import utilities.*; and I have to manually import every class?
You can't use a wildcard in an import statement to import other packages, it's just for classes.
So you could do:
import utilities.consoleredirect.*;
import utilities.generalutils.*;
import utilities.sqlhandling.*;
import utilities.tweetshandling.*;
If you're using a sensible IDE, you won't need to think about this very much. Just try and use a class by name and the import statement will be added automagically.
I want to rename entire package and it's all ocurences includeing package name and imports, change in eclipse.
For example com.google.gdata.client and its classes to com.xyz.google.gdata.client and its all occurences.
Actually, I want to customize gdata-core.1.47.jar source code as per my requirement. First thing I need to do is to change the package structure as per my requirements. But when I followed the above mentioned steps, some more imports were automatically added
For example before refctor,
For class com.google.api.gbase.client has following import
import com.google.gdata.util.common.xml.XmlWriter;
import com.google.gdata.data.Extension;
import com.google.gdata.data.ExtensionProfile;
import com.google.gdata.data.AttributeHelper;
import com.google.gdata.data.ExtensionDescription;
import com.google.gdata.util.ParseException;
import com.google.gdata.util.XmlParser;
But after after rename it to com.google.gdata.client to com.xyz.google.gdata.client it add some more imports like below,
import com.google.api.gbase.client.AddValueHandler;
import com.google.api.gbase.client.AttributeHistogram;
import com.google.api.gbase.client.GoogleBaseAttributeId;
import com.google.api.gbase.client.GoogleBaseAttributeType;
import com.google.api.gbase.client.GoogleBaseEntry;
import com.google.api.gbase.client.UniqueValue;
import com.google.gdata.util.XmlWriter;
import com.xyz.google.gdata.data.AttributeHelper;
import com.xyz.google.gdata.data.Extension;
import com.xyz.google.gdata.data.ExtensionDescription;
import com.xyz.google.gdata.data.ExtensionProfile;
import com.xyz.google.gdata.util.ParseException;
import com.xyz.google.gdata.util.XmlParser;
In the Project Explorer, right click the package name and choose Refactor->Rename.