Android - Parsing large files using SAX parser - android

I am trying to parse the xml data coming from webservice using SAX parser, when i try to parse the data(size:7.4MB) using URL, it works fine but when I copy the xml data from the URL and place the xml file(size:7.4MB) in the raw folder, the parsing fails.
When the size of file placed in raw folder is reduced to 1.95MB, it works fine. I have tried shuffling the tags to check if there are any issues with the data, I haven't found any.It works fine as long as the size doesn't exceed 1.95MB. Is there any size limit while parsing the data from raw folder in android? if yes what is the limit? or How to parse the large files using SAX parser?
Any pointers will really help me. Thanks in advance for your time and any help offered.
Regards,
Ramesh
02-14 17:35:35.651: DEBUG/asset(11035): Data exceeds UNCOMPRESS_DATA_MAX (2138421 vs 2097152)
02-14 17:35:35.651: WARN/dalvikvm(11035): threadid=9: thread exiting with uncaught exception (group=0x4001d7d0)
02-14 17:35:35.659: ERROR/AndroidRuntime(11035): FATAL EXCEPTION: Thread-13
02-14 17:35:35.659: ERROR/AndroidRuntime(11035): java.lang.AssertionError: java.io.IOException
02-14 17:35:35.659: ERROR/AndroidRuntime(11035): at android.util.Xml.parse(Xml.java:89)
code
try {
System.out.println("1");
//Xml.parse((url.openConnection().getInputStream()), Encoding.UTF_8, datahandler);
Xml.parse(getResources().openRawResource(R.raw.sample), Encoding.UTF_8, datahandler);
System.out.println("2");
//xr.parse(new InputSource(getAssets().open("sample.xml")));
}catch(Exception e){
System.out.println("Ramesh"+"XML Parsing exception:"+e);
}
error
Android DEBUG/asset(11035): Data exceeds UNCOMPRESS_DATA_MAX (2138421 vs 2097152)
WARN/dalvikvm(11035): threadid=9: thread exiting with uncaught exception (group=0x4001d7d0)
ERROR/AndroidRuntime(11035): FATAL EXCEPTION: Thread-13
ERROR/AndroidRuntime(11035): java.lang.AssertionError: java.io.IOException
ERROR/AndroidRuntime(11035): at android.util.Xml.parse(Xml.java:89)
ERROR/AndroidRuntime(11035): at com.infosys.gss.ui.Login$2$1.run(Login.java:431)
ERROR/AndroidRuntime(11035): Caused by: java.io.IOException

Related

Qoppa PDF Android NullPointer

I`m trying qoppapdf in my App and it runs into an NullPointer in the following code:
PDFDocument pdf = null;
try {
pdf = new PDFDocument(url, null);
} catch (PDFException e) {
e.printStackTrace();
}
PDFPage page = pdf.getPage(0);
The error reads:
06-01 17:29:59.687 24761-24761/app W/dalvikvm﹕ Exception Ljava/lang/NullPointerException; thrown while initializing Lcom/qoppa/android/pdfProcess/PDFPage;
06-01 17:29:59.687 24761-24761/app D/AndroidRuntime﹕ Shutting down VM
06-01 17:29:59.687 24761-24761/app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x413d22a0)
06-01 17:29:59.757 24761-24763/app D/dalvikvm﹕ GC_CONCURRENT freed 2569K, 26% free 10659K/14343K, paused 4ms+13ms, total 68ms
06-01 17:29:59.757 24761-24761/app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.qoppa.android.pdfProcess.PDFDocument$1.b(Unknown Source)
at com.qoppa.android.pdfViewer.e.p.b(Unknown Source)
at com.qoppa.android.pdfProcess.PDFDocument.b(Unknown Source)
at com.qoppa.android.pdfProcess.PDFDocument.<init>(Unknown Source)
at com.qoppa.android.pdfProcess.PDFDocument.<init>(Unknown Source)
at com.qoppa.android.pdfProcess.PDFDocument.<init>(Unknown Source)
The url which is used as input is valid and works fine with other PDF-Viewer.
Does anyone experienced this or similar problems? Am I doing it wrong?
I would be pleased to hear from you :-)
Please add the following code before loading the document:
//this static allows the sdk to access font assets,
//it must be set prior to utilizing libraries
StandardFontTF.mAssetMgr = getAssets();

java.lang.NumberFormatException (parse.Int)

An app published on market has an error:
java.lang.NumberFormatException
below the stack.
Is the cause this code?
fade = Integer.parseInt(ListPreference);
I see "OTHER" devices has affected by this crash. Any idea?
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Notify}: java.lang.NumberFormatException: unable to parse '' as integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3768)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: unable to parse '' as integer
at java.lang.Integer.parseInt(Integer.java:362)
at java.lang.Integer.parseInt(Integer.java:332)
at com.example.app.Notify.onCreate(Notify.java:33)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
... 11 more
java.lang.NumberFormatException: unable to parse '' as integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
==> it seems you are trying to parse an empty string. You should include the parsing operation in a try/catch block and deal with malformed inputs.
as in log :
NumberFormatException: unable to parse '' as integer
you are trying to parse space to integer . before parsing string value to Integer check for null or empty
Actually, There is any symbol or character happen in String ListPreference,
Its better to Handle this exception.
try {
fade = Integer.parseInt(ListPreference);
} catch (NumberFormatException e) {
Log.e("Exception",e.toString());
}
Update:
Look at the Jakarta Commons :
NumberUtils.isNumber()
This can be used to check most whether a given String is a number.
Also before using String ListPreference just removed white space from it using trim().
Using ListPreference.trim() and also check the length of ListPreference whether length is greater than 1 or not.
like, ListPreference.length() > 1

NoSuchMethod exception while creating and formatting .doc file using Apache poi-3.8 beta hwpf

I am getting following Exception when trying to run this code.
java.lang.NoSuchMethodError: org.apache.poi.POIDocument.< init >
Code Snippet:
try {
File file = new File(externalPath + "/abc.doc");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
CharacterRun run = range.insertAfter("Hello World!");
run.setFontSize(2 * 18);
run.setBold(true);
run.setItalic(true);
run.setCapitalized(true);
OutputStream out = new FileOutputStream(new File(externalPath + "/agnew.doc"));
doc.write(out);
out.flush();
out.close();
} catch (Exception ex) {
Log.e("Exception==","=="+ex.toString());
ex.printStackTrace();
}
Logcat:
Logcat : FATAL EXCEPTION: main : java.lang.NoSuchMethodError: org.apache.poi.POIDocument. :
at org.apache.poi.hwpf.HWPFDocumentCore.(HWPFDocumentCore.java:145) :
at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:218) :
at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:186) :
at com.vikas.prudent.CreateDocument.onCreate(CreateDocument.java:45) :
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) :
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) :
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) :
at android.app.ActivityThread.access$2300(ActivityThread.java:125) :
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) :
at android.os.Handler.dispatchMessage(Handler.java:99) :
at android.os.Looper.loop(Looper.java:123) :
at android.app.ActivityThread.main(ActivityThread.java:4627) :
at java.lang.reflect.Method.invokeNative(Native Method) :
at java.lang.reflect.Method.invoke(Method.java:521) :
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) :
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) :
at dalvik.system.NativeStart.main(Native Method)
Just looking at the exception, it appears to be lib version mis-match. Looks like HWPFDocumentCore.java:145 is trying to construct a new POIDocument but cannot find the expected constructor to call. I would take a look at line 145 of HWPFDocumentCore.java and see what constructor it is expecting. Then look for a POI library which has such a constructor in the POIDocument.
It sounds like you have two copies of Apache POI on your classpath, and old one and a new one. My hunch is that your HWPF jar (Scratchpad) is new, but it's picking up an old core POI jar, which is why you're getting the exception.
What you need to do is review all the jars on your classpath, and identify the POI related jars, then ensure you have a consistent set of them.
The POI FAQ has and entry on this very problem, along with some Java code you can use to print out which jar the POI classes come from. If you can't spot the wrong jars directly, try porting something like the code shown there to your android code to help you find the older jar.

how to add username and password in android in http request

how to add username and password in http request to call web service? I have write REST web service and if user want to do request ,he neeed to request like this in terminal :
curl -u username:password http://localhost:8080/user/folder
httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1),
new UsernamePasswordCredentials("kyaw", "password"));
get.setHeader("Authorization","Basic a31hdzpwYXNzd29yZA==");
I used either way to do in android but get exception :
05-20 07:13:30.900: DEBUG/AndroidRuntime(557): Shutting down VM
05-20 07:13:30.900: WARN/dalvikvm(557): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-20 07:13:30.972: ERROR/AndroidRuntime(557): FATAL EXCEPTION: main
05-20 07:13:30.972: ERROR/AndroidRuntime(557): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.put}: java.lang.RuntimeException: Binary XML file line #18: You must supply a layout_width attribute.
05-20 07:13:30.972: ERROR/AndroidRuntime(557): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-20 07:13:30.972: ERROR/AndroidRuntime(557): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
How do i do?
The error is "You must supply a layout_width attribute" (copy pasted from your stack trace).
The error is unrelated to the code you are showing. You are missing a layout_width="" attribute in one of your components XML declaration.

NullPointerException after finishing SFTP transfer

I'm receiving a null pointer execption at the end of a SFTP session.
What am I missing ?
This the error :
09-05 16:38:05.844 9298-9307/? E/System: Uncaught exception thrown by finalizer
09-05 16:38:05.844 9298-9307/? E/System: java.lang.NullPointerException
at com.enterprisedt.net.j2ssh.sftp.SftpFileOutputStream.finalize(SftpFileOutputStream.java:203)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
at java.lang.Thread.run(Thread.java:841)
NO errors from the library during the SFTP session.
Basically I log in to the SFTP server calling these functions :
boolean success = sftp.Connect(hostname,22);
..........
CkSshKey key = new CkSshKey();
..........
String privKey = key.loadText(keypath);
..........
key.put_Password(password);
...........
success = key.FromOpenSshPrivateKey(privKey);
...........
success = sftp.AuthenticatePk(mPrefs.getSftpSapUser(),key);
Then I send the file :
Boolean success = sftp.InitializeSftp();
.............
success = sftp.UploadFileByName(remoteFilePath,localFilePath);
.............
sftp.SetPermissions(remoteFilePath, false, 511);
What am I missing ?
Thanks
This is not a crash in Chilkat. Look closely at the exception information:
com.enterprisedt.net.j2ssh.sftp.SftpFileOutputStream
The crash is in another software vendor's class (EnterpriseDT). Or more accurately: It might be a crash caused by incorrect usage of that vendor's class. It's not necessarily a defect in that vendor's software. (I really don't know..)

Categories

Resources