I'm creating an Android application which uses RoboSpice for asynchronous network calls. Although I have no experience with RoboSpice, I've chosen for RoboSpice as it's regarded as one of the best on the internet, and because it can automatically convert JSON to POJO's. Unfortunately, the quality of the documentation of RoboSpice is a bit poor. Therefore my question:
I've succesfully used RoboSpice to make a network call to a REST GET method, automatically parse the JSON to a POJO and show the list of retrieved objects in an Android ViewPager. I'm using Jackson2GoogleHttpClientSpiceService to do this. Now, in this ViewPager I'm showing an image as well. Obviously, I want to download this image using RoboSpice. I've used one of the RoboSpice examples (which uses the OkHttpBitmapSpiceManager to download an image) as a guide and according to that I've added this line to my activity:
private OkHttpBitmapSpiceManager spiceManagerBinary = new OkHttpBitmapSpiceManager();
Also, I've added this line to the manifest:
<service
android:name="com.octo.android.robospice.spicelist.okhttp.OkHttpBitmapSpiceService"
android:exported="false" />
Now, as I'm not using maven for my Android project, I had to add the following jar to my project: robospice-ui-spicelist-1.4.9.jar (I've obviously added all the other necessary jar's for using the Jackson2GoogleHttpClientSpiceService, which works).
The problem is, the application fails to even start. Whenever I remove (or comment) the line containing the new OkHttpBitmapSpiceManager() the application works flawlessly. So apparently calling the constructor is what makes the application crash. I get the following error from the logcat:
java.lang.NoClassDefFoundError: com.octo.android.robospice.spicelist.okhttp.OkHttpBitmapSpiceService
To me, this error seems to relate to a missing jar or something. But I've added all the necessary jar's according to the documentation. Can someone with experience of RoboSpice explain to me what I'm doing wrong here? Should I add more jar's or am I missing something else? Or should I even use a completely different approach to loading images from a URL using RoboSpice?
EDIT!
To make it more clear, I've added the following jar's to my libs folder and the build path:
commons-io-1.3.2.jar
commons-lang3-3.1.jar
google-http-client-1.17.0-rc.jar
google-http-client-android-1.17.0-rc.jar
google-http-client-jackson2-1.17.0-rc.jar
guava-jdk5-13.0.jar
jackson-core-2.1.3.jar
jsr305-1.3.9.jar
robospice-1.4.9.jar
robospice-cache-1.4.9.jar
robospice-google-http-client-1.4.9.jar
robospice-ui-spicelist-1.4.9.jar
The problem is that you are not using a jar that contains the service class : com.octo.android.robospice.spicelist.okhttp.OkHttpBitmapSpiceService.
It is not contained in robospice-ui-spice-list but in robospice-okhttp. If you include this jar, you will get the service you need.
Have a look at this sample.
Also, please not that to download an image, it can be even easier to use non okhttp related classes. RS offers simple binary requests in its core package.
Oh, and btw, when you say "RS docs is a bit poor", please let us now via github or the mailing list how you would like to see it more complete. We also accept pull requests, even only for documentation.
Related
Hi I'm working on an Android app and I need to use GraphQL. I'm trying to use the Apollo client first by following this tutorial as practice but am having trouble following it through. It just lacks some specific information and details that would be helpful.
Currently what I'm stuck at is trying to construct a .graphql file. I was hoping to at least compile the code and make sure everything up to this point was fine, but apparently you can't even compile it without providing at least one .graphql file.
I've included the example given in the tutorial below, my confusion mainly comes from what exactly is "FeedQuery" and "FeedType"? Are they classes defined for this particular example or are they classes generated by Apollo itself to define any query? So should I just use those two classes when defining my own queries or make equivalents? And are those parameters also something required in the defintion or something specific to the examples strucutre?
I can't seem to find more information about this in their tutorial or website. It's tough enough trying to learn GraphQL but the lack of details in this tutorial is making things a lot more frustrating. If they had shared what the structure looks like in this tutorial it would have been really helpful but it doesn't seem to be included.
query FeedQuery($type: FeedType!, $limit: Int!) {
feedEntries: feed(type: $type, limit: $limit) {
id
repository {
name
}
postedBy {
login
}
}
}
Thank you for your help, and if anyone has a link to a better tutorial I'd really appreciate it.
I the context of the GraphQL DSL, FeedQuery is a named query (think of it as a method in Java terms) that you can use to retrieve specific data (as described by the internals of the query) from a GraphQL server.
To retrieve the desired data, you need to pass in two non-null arguments (denoted by the !), the feedType and the limit. The first is a custom type defined by the GraphQL schema implemented by the server. The second is a GraphQL scalar type.
Both the FeedQuery and FeedType will be converted to Java objects during compilation phase. For queries, you will be provided with an appropriate builder to include all the necessary information to perform the actual call.
You can read a complete Java example here. It is a more complete version of the tutorial you are following.
I have a SOAP Web Service that i want to parse and use in my android project. I have read that there is a website that auto generates the java classes by importing the url (wsl2code) but it seems to have flaws. Additionally the sample they provide is not working. What is the best and correct way of generating java classes from a WSDL url for my android project?
Use ksoal2 library for soap service which is light weight for android but the think you have to create service call manually
To answer my own question, I have used the service of wsdl2code http://www.wsdl2code.com/pages/home.aspx . Just some information regarding that, it has some limitations like
Don't Support byref Variables , in class
Don't Support Boolean& Variables , in class
Don't Support Int64& Variables , in class
Methods that are boolean or a custom class are turned to void and must be modified manually
Overall though this website saved me since it would take me a while to create the classes I needed by myself. It might have taken me a while to modify the classes but still saved a lot of time.
I'm having a lot of doubts and after two days of searching I still haven't found a good answer for my problem.
I have an app's project that is already in the store and this project have lots of Activities, Fragments, Services, IntentServices, Layouts, and resources (images, strings, integers, colors, styles, raws, drawables, etc...).
Now, I need to implement a new app that is almost a copy of the first one where I need only to change the background, some resources (but almost 99% stay the same), and maybe in one or two fragments I'll need to change some code (implement different logic statements).
I decided and I think it's natural to convert the all project in an library project.
I did:
1º Create a new project called framework and configured as library. Copied all code and resources (with the exception of assets folder) from the original project to here.
2º In the original project I leave only the manifest, proguard file. I change the manifest and proguard file to reference the classes of the new library.
I tested the app to see if was still working and it was Ok. Until now I did only the separation.
Now, came the problem. I need to create a solution reusable,and scalar for the library that allows me to use it in different apps.
In my original project I created a subclass of Application class that I use for global variables.
Without any others ideas, I decided the following:
1º Convert my MyApplication class in an abstract class. Also, I create an interface ApplicationInterface with some methods like isBackgroundOverlayed() or getBackgroundResource() that I use in the fragments to change the backgrounds or any other logic from the originally defined.
2º In the App's project, I created a new Application class that extends the abstract class MyApplication and implements the interface ApplicationInterface and which is declared in the Application tag in the manifest file.
Conclusion: This all works and I was able to have two app's projects with different background and other images like logos and even change some code logic. An example is in the original App when the user press one certain button, the App shows a dialog choice. In the new app when the user press the button it execute one fragment (without choice).
My concerns: I don't feel this is the best solution for the problem or best practice or good "pattern".
Do you have any ideas?
Thank you in advance!
ps: Sorry if I haven't use this forum properly. I search for an answer but I didn't found any.
I think you have achieved what you wanted, but that was a lengthy and time consuming process. One more thing I would like to mention is you should not change library projects for different applications
As said on Android developers guide :
Library projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse.
you can read more from here
Also you have to figure out,which lib is doing which work in case you forget what changes you have made
I would suggest you to keep a separate copy of original project and then import it into new work space in Eclipse (by checking copy project into current work space so that you have a new copy of your project) and consider changing its package name to get a new project
you can refer ans on this link to see how to change package name`
Is there a definitive method of creating either a PDF or a MS Word Doc file within the app and email it immediately (and possibly, also store it).
I have been trying for quite some time and have found out the JAVA libraries: apwlibrary and iText. But both of them dont provide any tutorials of sorts.
Could anyone point me in the right direction?
EDIT: Come to think of it, is could an online PDF generator be used, first by sending the data to the service, then retrieve the result and save it on the phone?
I would recommend apache fop http://xmlgraphics.apache.org/fop/
you can use standard FOP to generate pdf.
Unless it is a core feature of your device to create a pdf file I would suggest not to do it yourself. Adding PDF creation is going to be quite a lot of work potentially depending on your performance needs. Java libraries will be easier to add but less performant. Native libraries combined with Java will be more hazzle to maintain build and bug fixing wise.
If you just need to email some information why dont you create a message text in html and use a intent to email it with the build in email program instead? Or if you want you could e.g. put the PDF generation on a server and just email a link..
I'm working right now with JasperReports, an open source library to create reports in Java and export them to PDF, DOC, XLS... Using it in conjunction with iReport to create a group of templates makes it really easy to create files filled with content from different types of sources (I'm using JavaBeans).
If you don't like the idea of having static templates (That's a bit annoying depending on your needs), you can always take a look at DynamicJasper (The examples on the website are great).
Good Luck!
I have used Apache POI. It seemed to work well. http://poi.apache.org/
This actually, http://poi.apache.org/hwpf/
First of all I'd like to mention I am very new to Java programming. This Android project is my first experience with Java. So for one task I need to strip HTML tags from a string. I was thinking about using this answer Remove HTML tags from a String to do this task. In order to do this I need to be able to import javax.swing.text.html.* and javax.swing.text.html.parser.*.
I went to the properties of my project and attempted to add this library to my project. I read that this was included in the rt.jar file which was located at /usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar
I was able to use the imports but it seems like it added a million libraries I am not using. Will this negatively effect my application? What is the correct way to add just the one extension?
You don't. Android doesn't use Swing. You'll need to use Android's API to create your UI and perform text parsing. Consider android.text.Html as a simple way to strip HTML from a string.