Link to home
Start Free TrialLog in
Avatar of opike
opike

asked on

Receving error: package X does not exist

I'm trying to compile a small test program that uses the java api to interface with google docs.
Here's is the full error message:

GoogleDocsUpdate.java:2: package com.google.gdata.data does not exist
import com.google.gdata.data.*;

My classpath is set to include gdata-client-1.0.jar which contains the path
com/google/gdata/data/<bunch of *.class files>
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Please post output of

jar tf gdata-client-1.0.jar
Avatar of opike
opike

ASKER

Here's the code I'm trying to compile.
import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;


class GoogleDocsUpdate
{


public static void main (String[] args)
{
	//The service name info being passed is for google's tracking purposes
	SpreadsheetService myService = new SpreadsheetService("exampleCo-exampleApp-1");
	
	myService.setUserCredentials("********@gmail.com", "********");
	


}



}

Open in new window

Avatar of opike

ASKER

Here's the output of jar tf gdata-client-1.0.jar

META-INF/
META-INF/MANIFEST.MF
com/
com/google/
com/google/gdata/
com/google/gdata/data/
com/google/gdata/data/extensions/
com/google/gdata/data/extensions/BaseEventEntry$EventStatus.class
com/google/gdata/data/extensions/BaseEventEntry$Transparency.class
com/google/gdata/data/extensions/BaseEventEntry$Visibility.class
com/google/gdata/data/extensions/BaseEventEntry.class
com/google/gdata/data/extensions/BaseEventFeed.class
com/google/gdata/data/extensions/Comments$Handler.class
com/google/gdata/data/extensions/Comments.class
com/google/gdata/data/extensions/ContactEntry.class
com/google/gdata/data/extensions/ContactFeed.class
com/google/gdata/data/extensions/Deleted.class
com/google/gdata/data/extensions/Email$Handler.class
com/google/gdata/data/extensions/Email$Rel.class
com/google/gdata/data/extensions/Email.class
com/google/gdata/data/extensions/EntryLink$Handler.class
com/google/gdata/data/extensions/EntryLink.class
com/google/gdata/data/extensions/EventEntry.class
com/google/gdata/data/extensions/EventFeed.class
com/google/gdata/data/extensions/ExtendedProperty$Handler.class
com/google/gdata/data/extensions/ExtendedProperty$Realm.class
com/google/gdata/data/extensions/ExtendedProperty.class
com/google/gdata/data/extensions/FeedLink$Handler.class
com/google/gdata/data/extensions/FeedLink.class
com/google/gdata/data/extensions/GeoPt$Handler.class
com/google/gdata/data/extensions/GeoPt.class
com/google/gdata/data/extensions/Im$Protocol.class
com/google/gdata/data/extensions/Im$Rel.class
com/google/gdata/data/extensions/Im.class
com/google/gdata/data/extensions/Image$Handler.class
com/google/gdata/data/extensions/Image$Rel.class
com/google/gdata/data/extensions/Image.class
com/google/gdata/data/extensions/Labels.class
com/google/gdata/data/extensions/MessageEntry.class
com/google/gdata/data/extensions/MessageFeed.class
com/google/gdata/data/extensions/Money.class
com/google/gdata/data/extensions/OrgDepartment.class
com/google/gdata/data/extensions/OrgJobDescription.class
com/google/gdata/data/extensions/OrgName.class
com/google/gdata/data/extensions/OrgSymbol.class
<rest truncated....>
That jar is not in your classpath
Please place the following as the first line in main and tell me what it prints
System.out.println(System.getProperty("java.class.path"));

Open in new window

SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)

opike,

If you need just one class, just import the one class:
import com.google.gdata.client.spreadsheet.SpreadsheetService;

If you need a second one later - import it again. You do not win anything by importing full packages (well - it makes the code smaller but...) . Especially when you are using third-parrty libraries - because if in some of them there is a class named as a standard Java one, you might end up using this class instead of the one you think you are using... (such as javax.management.Query and com.google.gdata.client.Query for example - not that you are trying to use these but just an example).
you also need to add gdata-base-1.0.jar to your classpath
Only if he needs a class from there... :) The code he tries to compile above does not need it really.
Avatar of opike

ASKER

SpreadSheetService.class is actually in the jar file gdata-spreadsheet-2.0.jar

I'm compiling with the following batch file:

set javahome=C:\progra~1\java\jdk1.6.0_18
set classpath=.;%javahome%;C:\dev\java\GoogleDocs\gdata-client-1.0.jar;C:\dev\java\GoogleDocs\gdata-spreadsheet-2.0.jar
set PATH=%PATH%;%javahome%\bin
javac -classpath "%classpath%" GoogleDocsUpdate.java

I changed the import statement to be:
import com.google.gdata.client.spreadsheet.SpreadSheetService;

So now the error is:
GoogleDocsUpdate.java:1: cannot find symbol
symbol  : class SpreadSheetService
location: package com.google.gdata.client.spreadsheet
import com.google.gdata.client.spreadsheet.SpreadSheetService;

gdata-spreadsheet-2.0.jar is in the correct directory:
C:\dev\java\GoogleDocs>dir
 Volume in drive C has no label.
 Volume Serial Number is D8E2-F857

 Directory of C:\dev\java\GoogleDocs

04/12/2010  07:47 PM    <DIR>          .
04/12/2010  07:47 PM    <DIR>          ..
04/12/2010  03:33 PM               248 compile.bat
04/12/2010  03:33 PM               202 compile.bat.bak
04/12/2010  12:08 PM            89,605 gdata-client-1.0.jar
04/12/2010  12:08 PM            89,605 gdata-client-1.0.zip
04/12/2010  12:08 PM            32,415 gdata-spreadsheet-2.0.jar
04/12/2010  12:08 PM            32,415 gdata-spreadsheet-2.0.zip
04/12/2010  12:05 PM         5,836,378 gdata-src.java-1.26.0.java.zip
04/12/2010  07:47 PM               504 GoogleDocsUpdate.java
04/12/2010  07:39 PM               510 GoogleDocsUpdate.java.bak
04/12/2010  04:29 PM             3,937 output.txt
04/12/2010  03:30 PM               227 run.bat
04/12/2010  03:28 PM               329 run.bat.bak
              12 File(s)      6,086,375 bytes
               2 Dir(s)  12,487,979,008 bytes free

> I changed the import statement to be:
> import com.google.gdata.client.spreadsheet.SpreadSheetService;

should be:

import com.google.gdata.client.spreadsheet.SpreadsheetService;

Avatar of opike

ASKER

Oops - you're right. Fixed that but now still receiving the original error:

GoogleDocsUpdate.java:2: package com.google.gdata.data does not exist
import com.google.gdata.data.*;
See my earlier comment. you can remove that import
The spreadsheet import has nothing to do with your problem
Avatar of opike

ASKER

You're right... and I also did need to add the gdata-core-1.0.jar to my classpath. It's now compiling. I'll split the points evenly.
glad I could help :)
for the benefit of others reading this question, you really should accept the comments that actually fixed your problem :)
For anyone reading this question the comment that actually fixed the problem was 30558314
Avatar of opike

ASKER

Uh...if you really want to split hairs, in comment 30556298 Venabili was the first one to allude to the fact that the import com.google.gdata.data.* line could be removed.
that was fine, though the import wasn't the root of the problem, it was just unnecessary.
(and there *are* classes in that package)

Personally it doesn't bother me either way, just clarifying for others who have the same problem. Please don't take it personally, no malice intended :)

Avatar of opike

ASKER

No worries..I appreciate your and everyone else's help.
>and there *are* classes in that package

Not in the jar that he had in his classpath - which for him meant that there is no classes in that package that he had imported and which is the cause of the problem.. And I did ask him why he needs this import in the same comment :) And for the code he posted above, he really did not need the aditional jars. But let's not get there, can we - the asker was helped, everyone here actually had their part in helping which is what we all are here for, right?

opike,

:) Good that you got it working.
>  And for the code he posted above, he really did not need the aditional jars.

He did,  as already explained. That was the problem.
Feel free to test it if you don't believe us.
> He did

sorry make that

(s)he did

:)
>>Uh...if you really want to split hairs, in comment 30556298 Venabili was the first one to allude to the fact that the import com.google.gdata.data.* line could be removed.

Absolutely right

>>that was fine, though the import wasn't the root of the problem, it was just unnecessary.
(and there *are* classes in that package)

Wrong:
a. it *was* the root of the problem
b. there aren't any classes at that level, hence the error

For anyone reading the question later, the comment that correctly identified the problem was http:#30556298
does noone read comments anymore :)

> and I also did need to add the gdata-core-1.0.jar to my classpath.
For his full program most likely - not for the smallish one above.  He did not need the import for the few lines posted above.

Can we let this drop now?