MalformedJsonException only thrown during unit tests on Android Emulator - android

I have a test suite that open JSON files. The tests do not pass on emulator <= API 23 and work fine on newer API Level.
There are two different kinds of exceptions:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 1025 $.ajsonelement
and
com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 1025 path $.ajsonelement.
The weird thing is that those files work fine when I run the app and open them manually in the simulator.
I'm using gson but the problem also appears with Moshi.

Found the issue. The json files were in moduleName/src/test/resources/configs/. I moved them to moduleName/src/test/assets/configs/
The code to load them was:
val assetConfig = InstrumentationRegistry
.getInstrumentation()
.context
.assets
.open(configFileName)
val scanner = Scanner(assetConfig)
return scanner.useDelimiter("\\Z").next() Charsets.UTF_8))
I replaced it with a Guava helper:
val assetConfig = InstrumentationRegistry
.getInstrumentation()
.context
.assets
.open(configFileName)
return CharStreams.toString(InputStreamReader(assetConfig, Charsets.UTF_8))
Everything loads fine for all emulator between API 18 and 26.

Related

Tensorflow LSTM doesn't work

I've a problem with CRNN TensorFlow model when try to run it on Android (TensorFlowInferenceInterface). When I run it in Python environment everything seems to work correctly.
On Android I get following error:
java.lang.IllegalArgumentException: Expected len(indices) == values.shape[0], but saw: 25 vs. 30
[[Node: shadow/LSTMLayers/stack_bidirectional_rnn/cell_0/bidirectional_rnn/bw/bw/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3 = TensorArrayScatterV3[T=DT_FLOAT, _class=["loc:#shado.../transpose"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](shadow/LSTMLayers/stack_bidirectional_rnn/cell_0/bidirectional_rnn/bw/bw/TensorArray_1, shadow/LSTMLayers/stack_bidirectional_rnn/cell_0/bidirectional_rnn/bw/bw/TensorArrayUnstack/range, shadow/LSTMLayers/stack_bidirectional_rnn/cell_0/bidirectional_rnn/bw/transpose, shadow/LSTMLayers/stack_bidirectional_rnn/cell_0/bidirectional_rnn/bw/bw/TensorArray_1:1)]]
at org.tensorflow.Session.run(Native Method)
Any ideas?
len(indices) == values.shape[0], but saw: 25 vs. 30
The program expects these two values to be the same. It does not seem like an android error. Could you verify the dimensions of your tensors and see whether they match with what you expect them to be?

dropbox api exception android

When i tried to download a file from dropbox using dropbox api in android then i got a exception something like this
DropboxException:DropboxServerException (nginx): 400 Bad Request ('rev' is not well-formed: "/storage/sdcard0/SMSbackUpTOSS/DropBox/allSMS_01-Sep-2015.txt")
I am getting exception in this line
fd = mApi.getFileStream(fileSelected.path,
localFile.getPath());
Because no other line under this works.
But the same code in another project works fine. I dont understand why i am getting this exception!!!
mApi.getFileStream(fileSelected.path, localFile.getPath());
the second parameter here is rev, that is the revision of the file.
You should try to use null if you want the latest revision.

Android: RSS feed getting: XmlPullParserException: unexpected type (position:END_DOCUMENT null#1:1 in BufferedReader#216a7d6b)

I am getting the following exception trying to read an RSS feed:
XmlPullParserException: unexpected type (position:END_DOCUMENT null#1:1 in java.io.BufferedReader#216a7d6b)
W/System.err(18802): at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2054)
I've tried using the ksoap2-android-assembly libraries versions 2.4, 3.0 RC 4, 3.2.0, and 3.4.0 all with the SAME error on this feed:
http://vimeo.com/channels/karnschurch/videos/rss
(Which passes RSS validators just fine)
ENVIRONMENT:
Android Studio 1.1.0
Ubuntu 14.10 x64
Running on a Nexus 4 with 5.0.1
I've used the same code on dozens of other feeds with no errors. I know others have run into this issue and reported luck with different versions of the ksoap2 library (which is why I tried a few versions). But, nothing seems to help. My code is:
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(reader);
parser.nextTag();
return readFeed(parser);
It blows up on nextTag() and never gets to readFeed().
Any ideas on how I fix this?
Turns out it was just that I was using HttpURLConnection, but the link redirects to HTTPS. So, I just used HttpsURLConnection instead.

An error occured when attemping to generate client libraries

I've kept the updates ON in Eclipse, so may be Google app engine is causing the problem,Still didn't got the solution.
The Error log is here
java.lang.reflect.InvocationTargetException
at com.google.gdt.eclipse.appengine.swarm.wizards.GenerateSwarmApiAction$1.run(GenerateSwarmApiAction.java:82)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 17090
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:180)
at com.google.gson.Gson.fromJson(Gson.java:755)
at com.google.gson.Gson.fromJson(Gson.java:721)
at com.google.gson.Gson.fromJson(Gson.java:670)
at com.google.gson.Gson.fromJson(Gson.java:642)
at com.google.gdt.eclipse.managedapis.ManagedApiUtils.findAndReadDependencyFile(ManagedApiUtils.java:185)
at com.google.gdt.eclipse.managedapis.ManagedApiUtils.findAndReadDependencyFile(ManagedApiUtils.java:179)
at com.google.gdt.eclipse.managedapis.ManagedApiUtils.findAndReadDependencyFile(ManagedApiUtils.java:179)
at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmServiceCreator.copyToConnectedAndroidProject(SwarmServiceCreator.java:148)
at com.google.gdt.eclipse.appengine.swarm.wizards.helpers.SwarmServiceCreator.create(SwarmServiceCreator.java:453)
at com.google.gdt.eclipse.appengine.swarm.wizards.GenerateSwarmApiAction$1.run(GenerateSwarmApiAction.java:80)
... 1 more
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 17090
at com.google.gson.stream.JsonReader.expect(JsonReader.java:339)
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:322)
The Problem is:-
I've created a project with the app engine and was running perfectly but to due to some error in build path i've deleted the project and the app engine from the workspace and imported it again.
Now whenever i generate client libraries from app engine then this error is coming.
I've tried cleaning project,closing and reopening eclipse then also its not working
please help me.
Edit
I've copied the same code in new project and its working fine but not in old project
Did you clean the project ?
First for all these issues have to clean project.
If it remains the error then check with Android Library you are working with.
Be assured of using latest Android Library that is 4.3 to 4.4.2.
If still remains the issue there might be problem with Google Api package reference.
Then add Google API reference 4.3 by going to properties of the project
Expected BEGIN_OBJECT but was STRING at line 1 column 17090.
this line shows that there is an issue in your json input string that you are giving as a input to the gson. if you resolve this, your problem might be solved.
Please Turn off Google AppEngine Updates before proceeding the steps.
Steps to turn off Updates of eclipse is:-
1) Window->preferences->Install/Update->Automatic Updates(Uncheck it)
Steps followed while creating the new project which resolved me the error is:-
1) Create New Android project.
2) Right Click on project then Google->Generate App Engine Backend which creates a new project named Project-AppEngine
3) Copied all the Entities and the endpoints in AppEngine project.
4) Now I tried to generate the Cloud Endpoint Library and it worked.
This answer is just to escape the problem if you are facing it.

Invalid Argument while Creating Socket

I'm facing problem while creating a socket, with configuration as mentioned below,
Code :
sid = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
Error Details : Number - 22, String - Invalid argument
The error is not quite consistent. Out of 10 run this will happen for 3 - 4 times.
The code is compiled for the Android OS (For MAC & Windows platform it work for 10 out of 10).
Please suggest the possible reason and also fix for this.
Please check the permission of directory/path from where your executable run.
see this link for similar error and fix on windows
http://social.msdn.microsoft.com/Forums/en-US/wsk/thread/3076a9cd-57a0-418d-8de1-07adc3b486bb/

Categories

Resources