1

I am a beginner to android development, app development and development in general and I am trying to setup a backend database for my android application. I decided to use a service called back4app in order to have a more user-friendly experience with the database as I am also new to using databases too.

Anyways, I followed the tutorial that is located here which was an okay tutorial except that it was a bit out of date. At the end of the tutorial it states that my oncreate method in the mainactivity should look like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Parse.initialize(this);

    ParseInstallation.getCurrentInstallation().saveInBackground();
}

When I enter in this code I get a syntax error that says this:

initialize (com.parse.Parse.Configuration) in Parse cannot be applied to (com.example.zica.spartanjcapp.MainActivity)

I have searched in several different areas and cannot find anything that relates to my problem or how to resolve it. I have also gone over the entire tutorial to ensure that I followed it to the T and I can ensure you that I have. If anyone would be able to help me resolve my issue, I would be very grateful. Thank you for taking the time to read this.  

Manuel
  • 14,274
  • 6
  • 57
  • 130
zicameau
  • 139
  • 1
  • 11
  • Please provide the full error stack trace. – Shoshi Oct 08 '18 at 09:48
  • Where can I find that? All I can find is the squiggly line underneath the problem area and I hovered over that to get the error I copied and pasted – zicameau Oct 08 '18 at 10:25
  • run your project again to generate the error. then from the logcat, copy all the error log and post in your question – Shoshi Oct 08 '18 at 10:33

3 Answers3

3

First, REMOVE any Parse references to your MainActivity.java, so it should look like this:

import com.parse.ParseObject;
import com.parse.ParseUser;

// Import whatever Parse classes you need here...

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Remove ALL Parse references, do NOT use them here...
    }
}

Then, in your App.java file, do this:

import com.parse.Parse;

// Add/keep other imports as required...

public class App extends Application {
@Override
public void onCreate() {
    super.onCreate();
    Parse.initialize(new Parse.Configuration.Builder(context: this)
            .applicationId("APP_ID_HERE")
            .clientKey("CLIENT_KEY_HERE")
            .server("SERVER_URL_HERE")
            .enableLocalDataStore() // <--- ADD THIS HERE!
            .build()
    );
}

Of course add the App.java file to your Manifest.xml like so:

<application
    android:name=".App"

    <!-- Add other settings, as required... -->

</application>

That should make localDatastore work for your app and remove any error messages.

WhiteEagle
  • 97
  • 1
  • 4
1

I guess the context which is used in Parse.initialize(this); cause the issue.

Try creating an Application class and call it App:

import com.parse.Parse;
import android.app.Application;  

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(this); // initialize it here
    }
}

Then just use this inside onCreate() of your Activity:

// Save the current Installation to Back4App
ParseInstallation.getCurrentInstallation().saveInBackground();

Just like their example.

Remember to add it inside your AndroidManifest.xml:

<application
 android:name=".App"
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
1

I kindly ask you to make sure that you are using the latest version of the Parse SDK in your build.gradle (Module:app).

implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.18.5' // latest SDK version

And your repositories like this:

repositories {
    mavenCentral()
    jcenter()
    maven {
        url "https://jitpack.io"
    }
}

If so, please, double check your "App.java" file with your initialization code like this:

import com.parse.Parse;
import android.app.Application;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(new Parse.Configuration.Builder(context: this)
                .applicationId("<APP ID HERE>")
                .clientKey("<CLIENT KEY HERE>")
                .server("<SERVER URL HERE>")
                .build()
        );

    }
}
Charles
  • 531
  • 2
  • 11