Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Frustrating eclipse - cannot be resolved to a type ?

 
Arnold Strong
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really know what I am doing. I am just picking up random tutorials from the net and doing a Java project.
I made a "lib" folder in my eclipse project. Added the necessary JARs to build path.
When I try to make a simple "hello world" type of example, I get the same error "cannot be resolved to a type" at many places.
Looks like i have to import the JAR files by putting import statements, right ?
If yes, then how do i import the JAR files ?

Please help me.


 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1 -
Right click on project in Navigator or Project Explorer > Properties > Java Build Path > Libraries > Add jars > Add all jars in your lib folder

Option 2 -
Right click on project in Navigator or Project Explorer > Properties > Java Build Path > Libraries > Add external jars > Add jars from your hard disk
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of "project" did you start.

When you select "new project", Eclipse does most of the setup for you.

You then need to add dependent jars to your Java Build Path in the project properties.
Eclipse adjusts the .classpath file automatically.

I sense you are trying to do too much too quickly, even your comment about "random" examples.

Start small, there are in fact a ton of examples in the posts here. I simply copy them to a workspace and help!

WP
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually Willliam is right, you would not need any external jars for a hello World.
Simply create a java project and eclipse will add jre or jdk to your classpath and buildpath.
 
Arnold Strong
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:What type of "project" did you start.

When you select "new project", Eclipse does most of the setup for you.

You then need to add dependent jars to your Java Build Path in the project properties.
Eclipse adjusts the .classpath file automatically.

I sense you are trying to do too much too quickly, even your comment about "random" examples.

Start small, there are in fact a ton of examples in the posts here. I simply copy them to a workspace and help!

WP


I am not really a beginner anymore.
This is a "hello world" for google analytics using Java API.
The code below is from the google website.


Also see snapshot of project file structure. Dont know why all those folders are there.
ana.JPG
[Thumbnail for ana.JPG]
Snapshot from eclipse
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arnold Strong wrote:I am not really a beginner anymore.
This is a "hello world" for google analytics using Java API.
The code below is from the google website.



Thanks for the details, now I understand you're trying to quickly learn writing for google analytics but are not very accustomed with eclipse.
Here is what I think is wrong with your project -
- You need not copy all referenced libraries into lib.
- A valid JDK or JRE is not on your classpath - Since class Arrays is not identified.
Check if its a google's version of Arrays. Posting your import statements on top of the file will help.
They should be marked in red by eclipse too. When you work with java in eclipse( or any IDE for that matter ) first see if anything ir red in your import statements.
- Google jars are NOT on your classpath. Simplest way is to open the .classpath file. - Since classes like HttpTransport and Credentials are not identified.

Try the below-
GO to any red marked line > Press Ctrl + 1 > Fix project setup. See what happens and let us know.
Cheers!
 
Arnold Strong
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for helping me

Aniruddh Joshi wrote:
- You need not copy all referenced libraries into lib.


What is this lib folder really for ? Can't I just import all the Jars into the project instead ? If I do that, they appear in "referenced libraries" section when i expand the project folder.

Aniruddh Joshi wrote:
- A valid JDK or JRE is not on your classpath - Since class Arrays is not identified.
Check if its a google's version of Arrays. Posting your import statements on top of the file will help.
They should be marked in red by eclipse too. When you work with java in eclipse( or any IDE for that matter ) first see if anything ir red in your import statements


That error is due to AnalyticsScopes and not Arrays.

Aniruddh Joshi wrote:
- Google jars are NOT on your classpath. Simplest way is to open the .classpath file. - Since classes like HttpTransport and Credentials are not identified.


Do i have to open the classpath by going to the project folder each time or can i do it withing eclipse itself ?
How do i add stuff to the classpath. I had tried doing it manually once, but dont' know if it worked.

More importantly, how do i learn eclipse ? I prefer books that go from zero to advanced concepts. But there are none, except the one by lars vogel and that is too elementary.

Once again, thanks.
 
Arnold Strong
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giving up on the useless google API. I am doing Spring !
See you guys !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic