How can I solve this PicasawebService error? - java

I am just trying to get some things to work so I can try some of google app engines java. However I seem to have a problem with something that I can't get a hold of.
The java code looks like this:
import java.net.URL;
import com.google.gdata.client.photos.*;
import com.google.gdata.data.photos.*;
public class TestPicasa {
public static void main(String[] args) {
try {
PicasawebService service = new PicasawebService("Picasa test");
service.setUserCredentials("username#gmail.com", "password");
URL feedURL = new URL("http://picasaweb.google.com/data/feed/api/user/username?kind=album");
UserFeed feed = service.getFeed(feedURL, UserFeed.class);
for (AlbumEntry entry : feed.getAlbumEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have referenced to mail.jar, activation.jar, servlet-api.jar, gdata-client, gdata-client-meta, gdata-core, gdata-media, gdata-photos-2.0.jar and gdata-photos-meta-2.0.jar according to instruction from google.
And I get this error to the console:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:532)
at TestPicasa.main(TestPicasa.java:10)
Any idea on what I have missed?

You also need Google Collections

Verify that you are not loading your google jars twice. Sometimes you would have 2 locations and the one that you are not thinking about would have a missing jar. Then your class file gets missing since the jar it's on is not under 1st classloader. This happens often on Tomcat when you have all your jars in the webapp's WEB-INF/lib but some of the jars in the Tomcat/lib. Alternatively, I only found missing class in google-collect.jar and I don''t think you are listing it

Related

Missing class from package within Netbeans when using Spire.Doc.jar for docx files

I downloaded and installed the free Spire.Doc.jar file to work with .docx files. When I run it within Netbeans the functionality works fine however when I attempt to build the program I am getting the following error:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' less than -source '1.8'
Note: Creating static metadata factory ...
error: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1
not found
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1 not found
I have added the .jar file to my class path however there appears to be a class file missing from the com.spire.packages location.
Does anyone know if this is a Netbeans issue or does it look like there is an issue with the .jar file? I find it strange that it works when I run it within Netbeans but the above error occurs when I attempt to build the project.
I managed to get my application to build. What I had to do was remove the following code from my class and then it worked:
document.getMailMerge().MergeImageField = new MergeImageFieldEventHandler()
{
#Override
public void invoke(Object sender, MergeImageFieldEventArgs args)
{
mailMerge_MergeImageField(sender, args);
}
};
private static void mailMerge_MergeImageField(Object sender, MergeImageFieldEventArgs field)
{
String filePath = field.getImageFileName();
if (filePath != null && !"".equals(filePath))
{
try
{
field.setImage(filePath);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I'm not sure why it didn't work with this included however I got this code from the following website:
https://www.c-sharpcorner.com/article/how-to-perform-mail-merge-in-word-document-in-java/
therefore I will inform them in case this happens to someone else in the future.

OCR Logger Could Not be Resolved-Java

So I am trying to get an OCR working for a bigger project that reads characters from an image and I am following this you tube video: https://www.youtube.com/watch?v=aEMSxiXctPk
I did everything in the video and still cannot get it to work. I looked on this forum about the error I am getting, but it looks like their projects are different so I think they need different jars than I would. I have all of the jars from the video or at least I think I do. Any ways, the issue in java delivered this message.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type org.slf4j.Logger cannot be resolved. It is indirectly referenced from required .class files
org.slf4j.Logger cannot be resolved to a type
LoggerFactory cannot be resolved
The method setDatapath(String) of type Tesseract must override a superclass method
This is my code:
package Tess4j;
import java.io.*;
import net.sourceforge.tess4j.*;
import org.slf4j.*;
public class test {
public static void main(String[] args) throws IOException{
File imageFile = new File("C:\\Users\\Sean\\workspace\\Bigno Tracker\\Images\\eurotext.png");
ITesseract instance=new Tesseract();
instance.setDatapath("C:\\Users\\Sean\\workspace\\Bigno Tracker\\tessdata");
try {
String result=instance.doOCR(imageFile);
System.out.println(result);
}catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
This is an image of my screen that shows the jars I have.
So what am I missing?
Thanks in advance.
Edit:
I don’t really understand your question but, I’ve done some work with OCR Engines in the past.. ABBYY hass a good one that’s really easy to integrate!
P.S Did a little research, check to see if you have all the appropriate dependencies for your OCR engine version
Cheers

ClassNotFoundException when using Rserve in Java

I've imported all the necessary library files, and it works fine when I do a unit test using JUnit. But, when I run this code in the webapp, I get a ClassNotFoundException. I've commented out all the code that did not cause
the exception to occur. It seems the line "connection = new RConnection()"
is causing the problem.
I've also tried importing a different version of the Rserve library files, Rserve-0.6.5, with no success.
[update]
I've already added the Rserve and Rengine jars to the Build path for my project using Eclipses options.
Code:
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
public class RServerAccessor implements ProductInfoDAO {
private RConnection connection;
public List<Product> getProducts(String path) {
List<Product> list = new ArrayList<Product>();
try {
connection = new RConnection();
//connection.eval("source('~/Desktop/Food/workspace/mcApp2/rScripts/ReceiptReader.R')");
//REXP raw = connection.eval("getProducts(\"" + path + "\")");
//String text = raw.asString();
//System.out.println(text);
// String[] items = text.split("\n");
// for(String item: items){
// list.add(new GroceryProduct(item));
// }
} catch (RserveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
connection.close();
}
return list;
}
}
Exception:
Jan 02, 2017 9:27:09 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Service
java.lang.ClassNotFoundException: org.rosuda.REngine.Rserve.RserveException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at ctrl.Service.init(Service.java:41)
Any help appreciated.
Okay I tried these things and got it working.
Tested in Junit -> Works
In the full webapp -> Doesn't work (ClassNotFound)
Seperated the RConnection into it's own pure Java program -> works but gives this warning:
"will not be exported or published, Runtime ClassNotfoundExceptions may result" Someone on StackOverflow solved a similar problem here Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result by adding the lib files to the WEB-INF/lib of their project, however, this is not a web app so there is no such folder here. I tried this method in the actual web app with No success
I tried copying the RServe and REngine library jars files into the tomcat libs folder. e.g: /tomcat/lib/ and THIS WORKED.

How to use ROME in Intellij?

How can I set up my project in Intellij to use the ROME library to read a RSS Feed?
So far, I've developed the following:
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import java.net.URL;
public class ReadRSS {
public static void main(String[] args) {
String urlString = "http://news.ycombinator.com/"
boolean ok = false;
if (args.length==1) {
try {
URL feedUrl = new URL(urlString);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
System.out.println(feed);
ok = true;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
System.out.println("The first parameter must be the URL of the feed to read.");
System.out.println();
}
}
}
But, I get multiple errors when running my code, mainly of the variant:
.. java:package com.sun.syndication.feed.synd does not exist..
How do I import the package in Intellij? Managed to import this my adding jar in my project structure.
But the next problem is: I can't access org.jdom.Document - though I have installed jdom in my project structure. The error I get is
Error:(16, 38) java: cannot access org.jdom.Document class file for
org.jdom.Document not found
How can I resolve this?
If you're using Maven or gradle add the dependency in your configuration file (ex. pom.xml in Maven) and do a build/install to download your dependencies. It should work fine after that. Dependency info is here: http://mvnrepository.com/artifact/rome/rome/0.9
Otherwise add the jar (downloadable from the link above) manually to your project. Look at the first answer in this question to see how to do this: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
I'm a developer of the ROME team. The latest version is ROME 1.5. It can be obtained from the central maven repository: http://search.maven.org/#artifactdetails%7Ccom.rometools%7Crome%7C1.5.1%7Cjar
The groupId has changed to com.rometools in v1.5.0.#
I highly recommend you to use Maven, Gradle or another build tool that is able to resolve transitive dependencies so you won't have to collect all dependencies manually.

Boilerpipe Starter issue

I am new to boilerpipe. I tried to run sample code given on their website:
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.extractors.DefaultExtractor;
public class TESTURLBOILERPIPE {
public static void main(String[] arges) throws Exception
{
final URL url = new URL(
"http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en");
ArticleExtractor ae = new ArticleExtractor();
System.out.println(ae.INSTANCE.getText(url));
}
}
I have added all the required jar files to the class path, however I get the exception:
Exception in thread "main" java.lang.IllegalArgumentException: usage: supply url to fetch
at org.jsoup.helper.Validate.isTrue(Validate.java:45)
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:26)
I don't know Boilerpipe, but are you sure you are trying to run the correct Java class? The stack trace looks like you are trying to run HtmlToPlainText (without arguments, thus the exception), but from the code you posted I think you would like to run your TESTURLBOILERPIPE class.
Try using a python wrapper. It takes care of all the dependencies, though you might have to install jpype manually (that source code is on sourceforge).
https://github.com/misja/python-boilerpipe

Categories