Sabir Moglad
Sabir Moglad

Reputation: 889

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 ran the code, I got Parse: failure!
I don't know what is wrong with my code

Upvotes: 1

Views: 511

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191701

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

Upvotes: 3

Related Questions