Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to connect to Google books from android
    text
    copied!<p>Lets start from the top. I am trying to create an application that takes a ISBN then connects to Google Books and from there grabs the information about the book. I was able to do this using plain java:</p> <pre><code>import java.net.URL; import com.google.gdata.client.books.BooksService; import com.google.gdata.client.books.VolumeQuery; import com.google.gdata.data.books.VolumeEntry; import com.google.gdata.data.books.VolumeFeed; public class books { public static void main(String[] args) { //////////////////////////////////////////////// try { BooksService booksService = new BooksService("UAH"); String isbn = "9780262140874"; URL url = new URL("http://www.google.com/books/feeds/volumes/?q=ISBN%3C" + isbn + "%3E"); VolumeQuery volumeQuery = new VolumeQuery(url); VolumeFeed volumeFeed = booksService.query(volumeQuery, VolumeFeed.class); VolumeEntry bookInfo=volumeFeed.getEntries().get(0); System.out.println("Title: " + bookInfo.getTitles().get(0)); System.out.println("Id: " + bookInfo.getId()); System.out.println("Authors: " + bookInfo.getCreators()); System.out.println("Description: "+bookInfo.getDescriptions()+"\n"); }catch(Exception ex){System.out.println(ex.getMessage());} ///////////////////////////////////////////////// }} </code></pre> <p>I used the jars books and client from \gdata-src.java-1.46.0\gdata\java\lib with the dependencies from google-api-java-client-1.5.0-beta\dependencies and it worked perfectly. when I tried to convert it to android it gave me the error "Conversion to Dalvik format failed with error 1" so it would not compile. I then tried doing the android tools -> fix projects and still no luck I tried change the levels in build targets. I have cleaned it 100 times and still it didn't work. So then I decided to remove the google-api-java-client-1.5.0-beta\dependencies (the jars causing the error) and then it would compile but crash because </p> <pre><code>11-02 20:44:27.093: WARN/System.err(485): java.lang.NoClassDefFoundError: com.google.gdata.client.books.BooksService </code></pre> <p>My android code is as follows:</p> <pre><code>import java.net.URL; import com.google.gdata.client.books.BooksService; import com.google.gdata.client.books.VolumeQuery; import com.google.gdata.data.books.VolumeEntry; import com.google.gdata.data.books.VolumeFeed; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class AndroidBooksApiActivity extends Activity { Button btnSearch; TextView tvTitle,tvISBN,tvAuthor,tvDatePublished; EditText etSearch; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnSearch=(Button)findViewById(R.id.btnFindBook); tvTitle=(TextView)findViewById(R.id.tvTitle); tvISBN=(TextView)findViewById(R.id.tvISBN); tvAuthor=(TextView)findViewById(R.id.tvAuthor); tvDatePublished=(TextView)findViewById(R.id.tvDatePublished); etSearch=(EditText)findViewById(R.id.etSearch); btnSearch.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { //String isbn; //isbn=etSearch.getText().toString(); String isbn = "9780262140874"; BooksService booksService = new BooksService("UAH"); URL url = new URL("http://www.google.com/books/feeds/volumes/?q=ISBN%3C" + isbn + "%3E"); VolumeQuery volumeQuery = new VolumeQuery(url); VolumeFeed volumeFeed = booksService.query(volumeQuery, VolumeFeed.class); VolumeEntry bookInfo=volumeFeed.getEntries().get(0); tvTitle.setText("Title: " + bookInfo.getTitles().get(0)); tvISBN.setText("ISBN: " + isbn); tvAuthor.setText("Authors: " + bookInfo.getCreators()); tvDatePublished.setText("DatePublished: "+bookInfo.getDates()+"\n"); }catch(Throwable ex){tvTitle.setText(ex.getMessage()); ex.printStackTrace();} } }); } </code></pre> <p>}</p> <p>If you have any more questions I will answer to the best of my ability. I am still learning so it is possible my error is something easy I am just not seeing.</p> <pre><code> java.lang.IllegalArgumentException: already added: Lcom/google/common/annotations/GwtCompatible; [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.dex.file.DexFile.add(DexFile.java:143) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main.processClass(Main.java:372) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main.processFileBytes(Main.java:346) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main.access$400(Main.java:59) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:294) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main.processOne(Main.java:313) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main.processAllFiles(Main.java:233) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.dx.command.dexer.Main.run(Main.java:185) [2011-11-03 14:25:51 - androidBooksApi] Dx at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [2011-11-03 14:25:51 - androidBooksApi] Dx at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [2011-11-03 14:25:51 - androidBooksApi] Dx at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [2011-11-03 14:25:51 - androidBooksApi] Dx at java.lang.reflect.Method.invoke(Unknown Source) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:652) [2011-11-03 14:25:51 - androidBooksApi] Dx at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:510) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241) [2011-11-03 14:25:51 - androidBooksApi] Dx at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) [2011-11-03 14:25:53 - androidBooksApi] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (org.joda.time.DateTimeZone$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is *not* an inner class. [2011-11-03 14:25:57 - androidBooksApi] Dx trouble processing "javax/transaction/HeuristicCommitException.class": Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library. This is often due to inadvertently including a core library file in your application's project, when using an IDE (such as Eclipse). If you are sure you're not intentionally defining a core class, then this is the most likely explanation of what's going on. However, you might actually be trying to define a class in a core namespace, the source of which you may have taken, for example, from a non-Android virtual machine project. This will most assuredly not work. At a minimum, it jeopardizes the compatibility of your app with future versions of the platform. It is also often of questionable legality. If you really intend to build a core library -- which is only appropriate as part of creating a full virtual machine distribution, as opposed to compiling an application -- then use the "--core-library" option to suppress this error message. If you go ahead and use "--core-library" but are in fact building an application, then be forewarned that your application will still fail to build or run, at some point. Please be prepared for angry customers who find, for example, that your application ceases to function once they upgrade their operating system. You will be to blame for this problem. If you are legitimately using some code that happens to be in a core package, then the easiest safe alternative you have is to repackage that code. That is, move the classes in question into your own package namespace. This means that they will never be in conflict with core system classes. JarJar is a tool that may help you in this endeavor. If you find that you cannot do this, then that is an indication that the path you are on will ultimately lead to pain, suffering, grief, and lamentation. [2011-11-03 14:25:57 - androidBooksApi] Dx 2 errors; aborting [2011-11-03 14:25:57 - androidBooksApi] Conversion to Dalvik format failed with error 1 </code></pre> <p>I have tried using the the deps in gdata-src.java-1.46.0.zip\gdata\java\deps and again that worked for the java app but not for the android one. When I use the deps folder in the android app it says that</p> <pre><code>11-03 20:48:50.894: WARN/System.err(334): java.lang.NoClassDefFoundError: com.google.gdata.client.books.BooksService </code></pre> <p>I know that can't be because the java application has a definition. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload