Parse Server Android Studio not showing information

点点圈 提交于 2019-12-12 04:12:02

问题


My problem is that my parse server wont get any information from my app. I have included error logs, starter class, and main class. My parse server shows no information being passed to it.

package com.karanvir.myapplication5;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        Parse.enableLocalDatastore(this);


        ParseObject object= new ParseObject("example");
                object.put("my number","123");
        object.put("my string","karn");
        object.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {

                if(e==null){
                    Log.i("hello","anything");
                } else {
                    Log.i("random","morerandom");
                }

            }
        });
        ParseAnalytics.trackAppOpenedInBackground(getIntent());

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

07-13 11:47:23.618 16945-16945/com.karanvir.myapplication5 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.karanvir.myapplication5, PID: 16945
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.karanvir.myapplication5/com.karanvir.myapplication5.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                                                                                 at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:158)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                              Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
                                                                                 at com.parse.Parse.getParseDir(Parse.java:499)
                                                                                 at com.parse.ParseCorePlugins.getLocalIdManager(ParseCorePlugins.java:328)
                                                                                 at com.parse.ParseObject.getLocalIdManager(ParseObject.java:87)
                                                                                 at com.parse.ParseObject.getOrCreateLocalId(ParseObject.java:1310)
                                                                                 at com.parse.ParseObject.saveEventually(ParseObject.java:1719)
                                                                                 at com.parse.ParseObject.saveEventually(ParseObject.java:1673)
                                                                                 at com.karanvir.myapplication5.MainActivity.onCreate(MainActivity.java:31)
                                                                                 at android.app.Activity.performCreate(Activity.java:6876)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                                 at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:158) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
/*
 * Copyright (c) 2015-present, Parse, LLC.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
package com.karanvir.myapplication5;

import android.app.Application;
import android.util.Log;

import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseUser;
import com.parse.SaveCallback;


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("783b7")
            .clientKey( "3b6")
            .server( "httpe/")
            .build()
    );

   /* ParseObject object = new ParseObject("ExampleObject");
    object.put("myNumber", "123");
    object.put("myString", "rob");

    object.saveInBackground(new SaveCallback () {
      @Override
      public void done(ParseException ex) {
        if (ex == null) {
          Log.i("Parse Result", "Successful!");
        } else {
          Log.i("Parse Result", "Failed" + ex.toString());
        }
      }
    });*/


    ParseUser.enableAutomaticUser();



  }
}
package com.karanvir.myapplication5;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        Parse.enableLocalDatastore(this);


        ParseObject object= new ParseObject("example");
                object.put("my number","123");
        object.put("my string","karn");
        object.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {

                if(e==null){
                    Log.i("hello","anything");
                } else {
                    Log.i("random","morerandom");
                }

            }
        });
        ParseAnalytics.trackAppOpenedInBackground(getIntent());

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

回答1:


I think you need to put this line after object.put(...);

object.saveInBackground();

Refer to http://docs.parseplatform.org/android/guide/ and see "Saving Objects" and "The Local Datastore." They have the following codes after putting information to the objects.

pinInBackground();
saveInBackground();

Also, a suggestion, your applicationID, clientKey, and your server address should be masked for security reasons.




回答2:


first you shouldn't expose any of this - applicationId, clientKey, server{or any other key} you should instead add it to your gradle.property like this way MyApiKey="2000000000000000" and get it, this way in your gradle buildTypes.each {it.buildConfigField 'String', 'TOKEN_API_KEY', MyApiKey} and you can use the key from any of your activity this way String my = BuildConfig.TOKEN_API_KEY so in your code for example you will have .clientKey(BuildConfig.TOKEN_API_KEY)

To your question you should log your response, not only will it make it easier for you to debug or view result value, you can set breakpoint and step into, out and see what is going on. to set log you need to Log.d(TAG, value) where TAG is private static final String TAG = yourClass.class.getSimpleName();




回答3:


You need to put the parse information into another class that extends Application.

Check out this answer I had on someone else post.

https://stackoverflow.com/a/45083774/8200290

Once you do that, the MainActivity can host your application for whatever you need. Let me know if you have any questions




回答4:


HERE'S THE SOLUTION TO HOW TO SET UP PARSE ON ANY ANDROID STUDIO PROJECT!

STEP 1: i wrote the following code under dependencies in the build.gradle(Module: ) :-

compile 'com.parse:parse-android:1.15.7' (NEXT SYNC YOUR GRADLE)

By doing this you'll be magically able to use the parse keywords and methods .

STEP 2: NOW HERE'S THE TWIST . YOU DON'T NEED TO HAVE THE STARTERAPPLICATION JAVA CLASS IN YOUR ANDROID PROJECT.

ALSO NO NEED TO HAVE ANY OTHER CLASS GUYS!

ALSO ADD THE FOLLOWING

/CODE TO BE PUT IN ANDROIDMANIFEST :/

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

NOW MOVE ON TO STEP 3

STEP 3: ******HERE'S THE IMPORTANT PART****

YOU HAVE TO INITIALIZE YOUR PARSE, (WITH THE LIMITED KNOWLEDGE I HAVE , I INITIALIZED IT IN THE ONCREATE FUNCTION IN MAINACTIVITY)

Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
        .applicationId("YOUR_APP_ID")
        .clientKey("YOUR_MASTER_KEY")
        .server("YOUR_SERVER_URL")
        .build()
);

AND YOU'RE DONE !!! YOU'VE SUCCESSFULLY SETUP PARSE!!!!!!!



来源:https://stackoverflow.com/questions/45070221/parse-server-android-studio-not-showing-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!