The import com.google cannot be resolved? - java

I am using a tutorial at this page:
http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
It tells me to change the main activity, everything is going well except for this error:
"The import com.google cannot be resolved"
The line highlighted is:
import com.google.android.c2dm.C2DMessaging;
What could be the problem? Should it be my project name instead of com.google? Because I have a java file that is Web.SMS.C2DMessaging.

Did you add c2dm.jar to your project's build path?
First copy the c2dm.jar to lib folder in your project (create one if there are none).
1.) Right click on your project and select Properties.
2.) Select Java Build Path and select Libraries tab.
3.) Click Add External JARs... button and choose the c2dm.jar from lib folder.
4.) Click Open and OK.

Related

Unable to find or load Main Class in Intellij 2019.4

I have been at this problem for a few days now, don't know why it is still happening. I have tried other solutions that have been posted on stackoverflow but no luck.
Below the following code is from the book crafting interpreters in java.
In IntelliJ 2019.4 this error always pop up when I am trying to run the .jar file.
Error: Could not find or load main class com.jam.Jam
Caused by: java.lang.ClassNotFoundException: com.jam.Jam
I have built the .jar file and setting the main class as com.jam.Jam and the class path for the .jar file as /home/username/Jam-Programming_Language/src/com/jam/Scanner.Scanner.
This is the layout of my project directory.
The following solutions I have tried:
Solution 1
Open Project Structure
Select Modules, then click on the module for which you want the
dependency
Choose the Dependencies tab
Click the '+' at the bottom of the page and choose the appropriate
way to connect to the library file. If the jar file is already
listed in Libraries, then select 'Library'.
and
Solution 2
Go to the Project Structure, click on Modules, and click on your
Module
Choose the "Dependencies" tab
Click the "+" button on the right-hand side and select "Jars or
directories..."
Add the directory(ies) you want (note you can multi-select) and
click OK
In the dialog that comes up, select "classes" and NOT "jar directory"
Make sure you're using that Module in your run target
It had no effect apparently. Any clue on what I should do?
Edit: Uploaded wrong screenshot, replaced screenshot.
Thanks to CrazyCoder for pointing out the errors in my project (silly mistakes). It seems that after I have resolved those mistakes.
I had to follow the solutions I have posted then rebuild the .jar file.
Afterwards I need to mark the src folder as a source root folder (right click folder -> Mark Directory as -> sources root)
Edit Configurations if pointing to wrong main class.
Set Project compiler output (File -> Project Structure -> Project) to a folder designated to hold the output (any folder basically in or outside the project).
The error says, it is trying to run: com.jam.testfile. Your class is called: com.jam.Jam.
Click the dropdown where it shows "testfile" with a little red X on it. Select "Edit Configuration." For the "Main class", select "com.jam.Jam". That's it!
BTW, the little red X means there is some problem with your configuration.

How can I avoid this Ant Build error?

What is this ant build error in eclipse?
When I click the Ant Build I have the error message shown below.
Build failed
Reason: Unable to find an Ant file to run.
Could you please help me solve it?
Quoting from here
Create a new project in Eclipse
After the project is created, look in the package explorer window pane on the left and right click on the src folder.
There are two methods for the next step, you could either add a New > Class, and then copy and paste everything from your old java file to the new class (make sure the class name is the same), or the better route would be to Import.
After clicking Import, select File System under the general folder. Click Next.
Browse for the java folder where your source files are located. Once you click ok, it will add all of the source files to the right pane.
Select which files you want to add and click Finish.
Now if you look at your Package Explorer window you should see the source files. Now just compile them, and the error shouldn't appear and you can run them just like before.

Eclipse doesn't see class/package in import

I use eclipse.
my problem description:
In import I see red underlyed strings. But if I navigate - I see source code.
How does it dispay?
How can I fix it?
You must adjust the project's build path, so it contains the missing packages.
Long answer
You may navigate every class that is known to the workspace. But if they are underlined it means they are not available when building the project.
Click on the node "Referenced Libraries" to see what's included. If your imported package JAR is not listed there, adjust the build path.
Right-click on the folder containing "com/epam/dentsply/service" and choose "Build Path/Use as Source Folder". Be sure to select the one directly containing the "com" directory with your java files.

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.

Eclipse WTP: "The import ___ cannot be resolved for" error in a JSP file for a class defined in project

A Visual Studio user struggling w/ Eclipse...
I imported a set of servlets/JSPs into a project in Oracle Workshop for Weblogic. /page.jsp has the following import statement:
import="com.foo.bar.*"
Eclipse is displaying an error:
The import com cannot be resolved.
The class that implements the above import is in /WEB-INF/src but I don't know how to build the class in Eclipse to resolve that error. I assumed Eclipse would automagically build the .java file and place the output in /WEB-INF/classes, but it's not doing that.
It could be that I haven't structured my project directories correctly so perhaps that's why Eclipse isn't building my source. Any suggestions? How can I get this to work?
First of all, /WEB-INF/src is a rather strange place to keep your java sources; you may want to move them out of /WEB-INF (into /src in project root, for example)
Either way, you need to tell Eclipse where your sources are and where you want classes built to. It's done in project properties dialog:
Right-click on your project in Eclipse, select Properties
Click on Java Build path on the left
Click source tab on the right
Click Add Folder button and add your source folder (/WEB-INF/src or wherever you moved it to)
Ensure Allow output folders for source folders is checked below
Under newly added source path select output folder and point it to /WEB-INF/classes or other location of your choice.

Categories