NullPointerException after finishing SFTP transfer - android

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..)

Related

Possible bug on Android Starter SDK initialization

I'm using the Starter SDK v3.13.2.8 to perform auto-suggest searches in an Android app. It works well on Android versions 9 and 4.2. But on Android 5.1.1 (API 22), the app crashes. Here's the stack trace:
11-01 16:24:09.022 341-430/com.example.myapp.debug E/AndroidRuntime: FATAL EXCEPTION: pool-2-thread-1
Process: com.example.myapp.debug, PID: 341
java.lang.NoSuchMethodError: No virtual method getActiveNetwork()Landroid/net/Network; in class Landroid/net/ConnectivityManager; or its super classes (declaration of 'android.net.ConnectivityManager' appears in /system/framework/framework.jar)
at a.a.a.a.a.v0.a(MapsUtils.java:23)
at a.a.a.a.a.v0.a(MapsUtils.java:20)
at a.a.a.a.a.h.e(AnalyticsTrackerExternal.java:6)
at a.a.a.a.a.h.d(AnalyticsTrackerExternal.java:1)
at a.a.a.a.a.h$c.run(AnalyticsTrackerExternal.java:50)
at a.a.a.a.a.h$i.run(AnalyticsTrackerExternal.java:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
In order for this exception to be thrown, I don't even need to dispatch the request. All I need to do is to initialize the map engine:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
MapEngine.getInstance().init(ApplicationContext(this)) {
Log.d("HereInit", "$it")
}
}
}
Before the app crashes, though, it's possible to see the log output from the MapEngine.init callback:
11-01 16:24:10.079 341-341/com.example.myapp.debug D/HereInit: NONE
Fix will be included in SDK 3.14 release. From all projects tab inside the portal, the new version which is 4.1 can be downloaded.

Can't start pocketsphinx in Unity3d game

I am trying to integrate PocketSphinx into my Unity3d project.
In order to do this, I have integrated the Android demo project into the Android Studio export of the Unity3d project.
When trying to the app, I get an exception saying that the following function retured -1.
public static final native void Decoder_setSearch(long var0, Decoder var2, String var3);
This method is being called when I start listening for voice commands:
recognizer.startListening("hello app", 10000);
Why does this happen? How can I resolve it?
It works perfectly in the PocketSphinx example project.
How I've set up the Recognizer:
Assets assets = new Assets(MyActivity.this);
File assetDir = assets.syncAssets();
recognizer = defaultSetup()
.setAcousticModel(new File(assetDir, "en-us-ptm"))
.setDictionary(new File(assetDir, "cmudict-en-us.dict"))
.setRawLogDir(assetDir)
.setKeywordThreshold(1e-45f)
.setBoolean("-allphone_ci", true)
.getRecognizer();
recognizer.addListener(MyActivity.this);
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
...and more info from logcat (complete file):
01-29 18:01:12.989 4237-4237/com.myName.pocketSphinxTest I/SpeechRecognizer: Start recognition "hello app"
01-29 18:01:12.989 4237-4237/com.myName.pocketSphinxTest D/AndroidRuntime: Shutting down VM
01-29 18:01:12.989 4237-4237/com.myName.pocketSphinxTest W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4157fd58)
01-29 18:01:12.989 4237-4237/com.myName.pocketSphinxTest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myName.pocketSphinxTest, PID: 4237
java.lang.Error: FATAL EXCEPTION [main]
Unity version : 5.2.2f1
Device model : Osterhout_Design_Group R7-W
Device fingerprint: R7/apq8084/apq8084:4.4.4/KTU84P/ODG_R7_V3.1.12:user/release-keys
01-29 18:01:13.019 4237-4237/com.myName.pocketSphinxTest I/Process: Sending signal. PID: 4237 SIG: 9
setSearch is called in startListening with the name of the search. The name of the search is "hello app" in your case. If the search "hello app" is not added before it returns -1 and throws exception. The source is available in pocketsphinx-android sources.
The error generally means you didn't add the search with the name "hello app" before, from your code you say that KWS_SEARCH has the same value of "hello app", but I think there is a typo. You need to double-check that you use the same string for the search name. I would recommend you to replace "hello app" string with KWS_SEARCH in startListening call.

Android.isUserAMonkey throws RuntimeException

I'm seeing exceptions when ActivityManager.isUserAMonkey() is run on older Android devices:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.AndroidApp}: java.lang.RuntimeException: Unknown exception code: 1 msg null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unknown exception code: 1 msg null
at android.os.Parcel.readException(Parcel.java:1257)
at android.os.Parcel.readException(Parcel.java:1235)
at android.app.ActivityManagerProxy.isUserAMonkey(ActivityManagerNative.java:2762)
at android.app.ActivityManager.isUserAMonkey(ActivityManager.java:990)
at <com.myapp....> ...
There is a bit of discussion of the bug here (including a classic thats-not-possible response from one of the developers: "In the standard platform implementation this is pretty much not possible.")
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/tQJcM4O4WxM
Its not clear to me if this always happens, or only happens when running under a test monkey, or only on some devices or what. (I'm running into this problem using Apkudo's device testing service, where the user is always a monkey.) Its not clear when this was fixed, either (it doesn't happen on most (all?) newer devices).
The exception seems to be restricted to Android 2.2 (SDK version 8) releases. And seems to have been a bug in android.app.ActivityManagerNative.
Here's the 2.2.1 code (found in ActivityManagerNative.java on grepcode.com):
1248 case IS_USER_A_MONKEY_TRANSACTION: {
1249 data.enforceInterface(IActivityManager.descriptor);
1250 reply.writeInt(isUserAMonkey() ? 1 : 0);
1251 reply.writeNoException();
1252 return true;
1253 }
Here's the 2.3.1 code (which seems to be the same as much more recent 4.x code which I know works correctly). (Also found on grepcode.com):
1248 case IS_USER_A_MONKEY_TRANSACTION: {
1239 data.enforceInterface(IActivityManager.descriptor);
1240 boolean areThey = isUserAMonkey();
1241 reply.writeNoException();
1242 reply.writeInt(areThey ? 1 : 0);
1243 return true;
1244 }
Notice the order of writeNoException and writeInt are reversed in the newer code. The corresponding code to read the parcel seems to be unchanged since 2.2.1 as far as I can tell:
2749 public boolean isUserAMonkey() throws RemoteException {
2750 Parcel data = Parcel.obtain();
2751 Parcel reply = Parcel.obtain();
2752 data.writeInterfaceToken(IActivityManager.descriptor);
2753 mRemote.transact(IS_USER_A_MONKEY_TRANSACTION, data, reply, 0);
2754 reply.readException();
2755 boolean res = reply.readInt() != 0;
2756 data.recycle();
2757 reply.recycle();
2758 return res;
2759 }
This side reads the exception first, then expects the data.
The javadoc for Parcel readException and writeException imply that they record the exception in the parcel's header (and thus shouldn't impact the actual data in the parcel), but it seems the order does matter.
This means on SDK version 8 the ActivietyManager.isUserAMonkey() API will always throw an exception, monkey or not. Android builds after SDK 8 should not throw this exception.
I suspect the SDK 8 exception message might be slightly different without a monkey ("1 msg null" vs. maybe "0 msg null"?), but don't have an example of the exception without a monkey running.

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.

Android - Parsing large files using SAX parser

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

Categories

Resources