Sabir Moglad Sabir Moglad - 1 month ago 5
Android Question

my local parse server is not working

I am trying to use Parse on my windows PC with android studio.

I followed some tutorials to install mongoDB, Parse server and Parse dashboard, and all went smooth.

when I open android studio, the parse server initializes but it doesn't save the data and I don't what went wrong

here is my manifest code:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".StarterApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="kooora.com100plus" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="kooora.com100plusMasterKey" />

<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


I changed the key and the client ID as the same ones when I set my parse Server

and here is the code for the start application activity:

public class StarterApplication extends Application {

@Override
public void onCreate() {
super.onCreate();

// Enable Local Datastore.
Parse.enableLocalDatastore(this);

// Add your initialization code here

Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("kooora.com100plus")
.clientKey("kooora.com100plusMasterKey")
.server("http://localhost:1337/parse/")
.build()
);


ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
Log.i("Parse", "Save Succeeded");
} else {
Log.i("Parse", e.getMessage());
}
}
});

ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}


after I run the code I got Parse: failure!

I don't know what is wrong with my code

Answer

.server("http://localhost:1337/parse/")

When you run the code in your app, localhost means "this device" AKA your Android device, not the server.

You need to use the IP address of the server there (which will depend if you are using an emulator or a physical device).