Can we create pdf reports from .jrxml in Android application, without a Jasper Server?

0

Dear Experts, Kindly guide,

I already using Jasper Reports in my standalone java application (without Jasper Server).  Now I am building a similar application on Android.

Can we create pdf reports from .jrxml in Android application, Without a Jasper Server?   Because my android application is standalone, it does not interact with webserver/appserver.

In all documentations & replies, I am not able to find how a pdf report (from .jrxml) can be created/generated on Android without a Jasper Server? 

Kindly reply
Ajeet

ajeetspune's picture
Joined: Apr 25 2020 - 4:44am
Last seen: 2 months 3 weeks ago

Dear All,  Pls refer below.. Need your help..

Thank you so much for your reply. Your reply boosted me to go further... and to target offline report display on Android Version, as it will help lot of people here in India, being Internet is not facilitated all the time..!!!

Having said, I need your help a bit further.. as i got stuck and the exception is occuring while executing .... loadObject

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(input);

Below is the build.gradle file attached, alongwith the Activity Class... 

We have implemented as following.. ,

implementation 'com.itextpdf:itextg:5.5.10'
implementation ('net.sf.jasperreports:jasperreports:6.0.3') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
exclude group: 'com.itextpdf'
}

--------------------- exception ------------------------------------------

2021-01-06 14:34:14.891 8630-8630/com.techinfu.billsmart W/zygote: Got a deoptimization request on un-deoptimizable method void com.android.internal.os.ZygoteInit.main(java.lang.String[])
2021-01-06 14:34:14.891 8630-8630/com.techinfu.billsmart D/AndroidRuntime: Shutting down VM
2021-01-06 14:34:14.898 8630-8630/com.techinfu.billsmart E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.techinfu.billsmart, PID: 8630
    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Font;
        at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.resolveObject(ContextClassLoaderObjectInputStream.java:130)
        at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1402)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2003)
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:504)
        at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:825)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1006)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1903)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1804)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374)
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:249)
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:233)
        at com.techinfu.billsmart.ui.customer.CustomerList.generateCustomerListReport(CustomerList.java:112)
        at com.techinfu.billsmart.ui.customer.CustomerList.onCreate(CustomerList.java:73)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Font" on path: DexPathList[[zip file "/data/app/com.techinfu.billsmart-kYWVPtN3srzFG7HPayxhPg==/base.apk"],nativeLibraryDirectories=[/data/app/com.techinfu.billsmart-kYWVPtN3srzFG7HPayxhPg==/lib/x86, /data/app/com.techinfu.billsmart-kYWVPtN3srzFG7HPayxhPg==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.resolveObject(ContextClassLoaderObjectInputStream.java:130) 
        at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1402) 
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) 
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2003) 
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:504) 
        at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:825) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1006) 
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1903) 
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1804) 
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354) 
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374) 
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:249) 
        at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:233) 
        at com.techinfu.billsmart.ui.customer.CustomerList.generateCustomerListReport(CustomerList.java:112) 
        at com.techinfu.billsmart.ui.customer.CustomerList.onCreate(CustomerList.java:73) 
        at android.app.Activity.performCreate(Activity.java:7009) 
        at android.app.Activity.performCreate(Activity.java:7000) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

ajeetspune - 3 months 2 weeks ago

2 Answers:

0

Yes, all you need is the Jasper Library.  This is how my company runs all of its reports.  From our UI we call the jasper report, execute it, then export to a PDF for review.

jgust's picture
317
Joined: Jun 10 2010 - 6:39am
Last seen: 1 hour 55 min ago
0

Dear, Thank you so much for your reply. Your reply boosted me to go further... and to target offline report display on Android Version, as it will help lot of people here in India, being Internet is not facilitated all the time..!!!

 

Having said, I need your help a bit further.. as i got stuck and the exception is occuring while executing .... loadObject

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(input);
 
Below is the build.gradle file attached, alongwith the Activity Class... 

We have implemented as following.. ,

implementation 'com.itextpdf:itextg:5.5.10'
implementation ('net.sf.jasperreports:jasperreports:6.0.3') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
    exclude group: 'com.itextpdf'
}

--------------------- exception ------------------------------------------

2021-01-06 14:34:14.891 8630-8630/com.techinfu.billsmart W/zygote: Got a deoptimization request on un-deoptimizable method void com.android.internal.os.ZygoteInit.main(java.lang.String[])
2021-01-06 14:34:14.891 8630-8630/com.techinfu.billsmart D/AndroidRuntime: Shutting down VM
2021-01-06 14:34:14.898 8630-8630/com.techinfu.billsmart E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.techinfu.billsmart, PID: 8630
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Font;
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.resolveObject(ContextClassLoaderObjectInputStream.java:130)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1402)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:504)
at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:825)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1006)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1903)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1804)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:249)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:233)
at com.techinfu.billsmart.ui.customer.CustomerList.generateCustomerListReport(CustomerList.java:112)
at com.techinfu.billsmart.ui.customer.CustomerList.onCreate(CustomerList.java:73)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Font" on path: DexPathList[[zip file "/data/app/com.techinfu.billsmart-kYWVPtN3srzFG7HPayxhPg==/base.apk"],nativeLibraryDirectories=[/data/app/com.techinfu.billsmart-kYWVPtN3srzFG7HPayxhPg==/lib/x86, /data/app/com.techinfu.billsmart-kYWVPtN3srzFG7HPayxhPg==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.resolveObject(ContextClassLoaderObjectInputStream.java:130)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1402)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:504)
at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:825)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1006)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1903)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1804)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:249)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:233)
at com.techinfu.billsmart.ui.customer.CustomerList.generateCustomerListReport(CustomerList.java:112)
at com.techinfu.billsmart.ui.customer.CustomerList.onCreate(CustomerList.java:73)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Attachments: 
ajeetspune's picture
Joined: Apr 25 2020 - 4:44am
Last seen: 2 months 3 weeks ago
Feedback
randomness