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.  

3
  • Please provide the full error stack trace. Commented Oct 8, 2018 at 9: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 Commented Oct 8, 2018 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 Commented Oct 8, 2018 at 10:33

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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"

2 Comments

Okay so I did this and it gives me the same error but it's just moved to the App class now instead.
Interesting. Did you check the imports? And did you check if you added the dependencies correctly?
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()
        );

    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.