I use this Parse Server Guide to create a local instance of the analysis server. I download and configure the example, and it works fine, but when I try to use the android SDK, I get this error
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens
W/System.err﹕ com.parse.ParseRequest$ParseRequestException: bad json response
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:290)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:308)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRequest$3.then(ParseRequest.java:137)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRequest$3.then(ParseRequest.java:133)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$15.run(Task.java:917)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task.completeAfterTask(Task.java:908)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task.continueWithTask(Task.java:715)
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task.continueWithTask(Task.java:726)
02-12 22:41:58.674 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$13.then(Task.java:818)
02-12 22:41:58.674 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$13.then(Task.java:806)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$15.run(Task.java:917)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ Caused by: org.json.JSONException: Value Cannot of type java.lang.String cannot be converted to JSONObject
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at org.json.JSON.typeMismatch(JSON.java:111)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:159)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:172)
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:298)
02-12 22:41:58.690 7211-7211/com.christoandrew.android.authens W/System.err﹕ ... 13 more
Here is my index.js
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/authens',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'UBXrCTUXuXf6fEBpbE7sHBamq4b0RdQcASFTHxo9',
masterKey: process.env.MASTER_KEY || 'ghFiFWGtdymY3oXqWDTDBz6RyW7XdMyWzjXoJjFb',
clientKey: '4m2WpkkGCX77w3FNq3JWT74nVgRKNsgTj10Q1s4t',
});
var app = express();
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
app.get('/', function(req, res) {
res.status(200).send('I dream of being a web site.');
});
var port = process.env.PORT || 1337;
app.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
This is how I initialize
Parse.enableLocalDatastore(this);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(getString(R.string.parse_app_id))
.clientKey(getString(R.string.parse_client_key))
.server("http://10.0.3.2:1337/parse")
.build());
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
as in the textbook. I use genymotion as my virtual device running in 10.0.3.2. Is there something that I don’t see or is it a common problem.
Update
If I use curl from cmd, it works fine
curl -X POST -H "X-Parse-Application-Id: UBXrCTUXuXf6fEBpbE7sHBamq4b0RdQcASFTHxo9" -H "X-Parse-Client-Key: 4m2WpkkGCX77w3FNq3JWT74nVgRKNsgTj10Q1s4t" -H "Content-Type: application/json" -d @json.txt http://localhost:1337/parse/classes/GameScore
source
share