简体   繁体   中英

Parse data from Parse.com in Android

I am new to parse.com and android studio. I tried to create a table in parse by simply giving some test data but when the app runs the emulator says "unfortunately the app has stopped" .

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.parse.Parse;
import com.parse.ParseObject;
public class fresh_app extends Activity {
    Button b1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fresh_app);
        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);

        b1=(Button)findViewById(R.id.button);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ParseObject testObject = new ParseObject("TestObject");
                testObject.put("foo", "bar");
                testObject.saveInBackground();
            }
        });
    }

The gradle dependicies are :

compile files('libs/Parse-1.10.3/Parse-1.10.3.jar')
    compile 'com.parse.bolts:bolts-android:1.+'

Okay, LogCat said it all - You need to put Parse.enableLocalDatastore(this); before Parse.initialize in Your class that extends Application (inside onCreate() ):

public class ParseApp extends Application{

@Override
public void onCreate(){
    Parse.enableLocalDatastore(this);
    Parse.initialize(this, key1, key2);
}
}

Also, no need for compiling files - You could just do: compile 'com.parse:parse-android:1.10.3'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM