The import com.example cannot be resolved - java

I am trying to compile this example given by Google on the protocol buffers:
https://developers.google.com/protocol-buffers/docs/javatutorial
It comes with a ListPeople.java and AddPerson.java file along with a bunch of imports. The problem is that i am getting "The import com.example cannot be resolved" as seen in this screenshot:
http://postimg.org/image/67whg6a57/full/
This is the full path of the import com.example java file:
http://postimg.org/image/wexoc4sez/full/
and where all of my files are located:
http://postimg.org/image/4veseacpn/full/
I've tried to do the following:
Project->Clean
File->Refresh
Property->Java build path->add external JAR:
http://postimg.org/image/xjrqhievv/full/
None of these has work. What is the problem?

So this seems to be code that is missing from your project. If you press Shift-Ctrl-T and type in AddressBook, is it there?
If it is not there then it has not been generated from the example .proto files as specifiied in the Google on the protocol buffers files

You're trying to add Java source files as if they're libraries - they're not.
Add the "src" directory as a Source Path (leftmost tab in the Java Build Path settings) instead. Or if that's already a source path, try refreshing it in package explorer. Either way, you definitely don't want to have source files as libraries...

Related

Unresolved import of external library with properties file in classpath

I'm working with usb4java at the high level following this demo: http://usb4java.org/quickstart/javax-usb.html. My issue is that we need javax.usb.properties in the classpath, so I've put it in the src directory. I've also loaded up the .jars into a lib directory and added them to the referenced libraries. After all of this when importing "javax.usb.*" I'm getting an import cannot be resolved error and none of the types are accepted.
Note: the properties file is populated with: "javax.usb.services = org.usb4java.javax.Services" as instructed.
Thoughts?
I think you need to add to the CLASSPATH also the JSR080 (javax.usb API). Where the javax.usb interface is defined. You can download from here: http://javax-usb.sourceforge.net/
I have checked and it looks the javax.usb API is included under lib folder in the usb4java-javax distribution: http://nexus.ailis.de/content/groups/public/org/usb4java/usb4java-javax/1.2.0/usb4java-javax-1.2.0.zip it is called usb-api.jar
Then make sure the javax.usb.properties file is on the root of your application CLASSPATH.

Java import error - org.jdom

I am attempting to edit code from an old developer.
I know it is bad practice but what she said I had to do was create a dummy project and then copy paste the packages in question modify what I need to modify then compile and copy the classes that I changed into the directory where the classes in use are stored.
So I created the dummy project and copied the packages/files into the source folder of the dummy project but I keep getting a "package org.jdom does not exist" error.
The error appears on the lines:
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
When I copied the folders/files into the source folder I copied the entire "org" directory.
You can see from my screenshot that the package is in the Project Explorer
I have several things to resolve the issue but none seemed to work.
I tried adding the "org" directory into the classpath environment variables.
I tried adding the "org" directory as a library to the project.
I have tried clearing the NetBeans cache after doing both of these but none of these 3 things worked.
Below is a screenshot of the projects src folder in file explorer
Can someone explain to me what I need to do to get this issue resolved?
I was adding the wrong files to the libraries section of my project.
I was adding the source for jdom when i should have been adding the jdom .jar file.
Thanks for the help guys.
install jdom at your library folder, there is a new version of jdom try to download it and install it in your project directory.

Java: How can I import Trident into my project?

I'm trying to use the Trident animation library in my project. I've added the trident.jar to the build path in my Eclipse project but I'm still getting a build path error. The archive required for the library is missing.
Maybe I'm being stupid, but I can't seem to find anything like this on the website. I thought the .jar was the only thing I needed based on examples from around the net. And there doesn't seem to be a full Eclipse project to import either.
If I'm missing something silly, please let me know. Thanks!
Here is the exact error: Description Resource Path Location Type
Archive for required library: '/home/josh/Software/Eclipse Java EE/Trident/trident.jar' in project 'SP-Reversi' cannot be read or is not a valid ZIP file SP-Reversi Build path Build Path Problem
The trident.jaris the only jar you need. The error message indicates, that your trident.jar is corrupted. Try to unjar the file:
jar -xvf trident.jar
IMHO this will produce an error. Try to download the jar once again...

In eclipse, is it possible to change what the default package is without changing the source folder?

I'm working with some people on a java project. Problem is, I'm the only one using eclipse. The source files are located in svn in trunk/src/*.java. However, if I import that as a project directory, the default package is "" instead of what the actual project package name is.
Is there a way to change that without changing the source location and the package name?
Thanks!
If you mean that you want code in package foo.bar without having a matching directory folder of foo/bar under some source root - no, I don't think Eclipse supports that. While the convention of source locations having to match package structure isn't enforced by the language specification, it's mentioned there and so widely respected that I think it would be a bad idea to do anything else.
Eclipse requires a directory structure that matches the package structure. There is no option to have some package prefix that isn't reflected in directories.
IntelliJ can work with this, and it's what most people expect to see most of the time anway.
I think you are checking out the incorrect root folder.
If you are trying to work with a collection of source files located under trunk/src/ you may be don't need to check out this folder, because you will loose your reference to the main package (for example foo.bar) because it will be the base package.
You may need to check out the trunk/ folder, because Eclipse expects to find the source files under the default /src folder. Once you have your main root folder (with a lot of files like .project, .classpath inside), it is likely possible that Eclipse will recognize your folder structure and configuration and your project will compile without problems.

How to take package .java files into a Eclipse Project

I've got a copy of a java package, with example implementation. The package is in a structure called com.java.project (folders, containing myriads of .java files) and there's also a few example files (example1.java, example2.java)
The example files have 'import com.java.project' calls in them, that's all well and good. However, I can't seem to work out how to get Eclipse finding the package contents (currently returns "Type not found" for any calls to the project objects.
I've tried placing the com structure in the same level as my example1.java, but that doesn't work. I have read that I need to compile the package into a .jar to get it to work w/Eclipse, but that doesn't seem to want to behave, none of the files compile.
In Eclipse you can right click on the Project Explorer and select "New -> Java Project"
Then you can import your java files by right clicking your project, selecting import from file system. If the class file shows an error, open the class file, the class name should have red curly braces, click on the error tick mark and Eclipse will give you an option to move the file to the correct package which in turn creates the folder structure for you.
1.Can you do a check on the build path of your Java project? (Right-click the project -> Properties -> Java Build Path -> Source tab), and see if the root folder contains the code is properly specified here.
2.Maybe a Project->Clean will help as well.
Hii,
Just Create a new project with File -> New menu
you need to open Java Perspective and there you will find a package named "src" you need to copy your "com" directory and paste it at the src folder.
I hope this will work for you.

Categories