Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
连接新的Android项目与解析服务器示例和解析仪表板(本地)_Android_Mongodb_Parse Platform_Parse Server - Fatal编程技术网

连接新的Android项目与解析服务器示例和解析仪表板(本地)

连接新的Android项目与解析服务器示例和解析仪表板(本地),android,mongodb,parse-platform,parse-server,Android,Mongodb,Parse Platform,Parse Server,我正在尝试将一个新的android项目与解析服务器示例(本地)连接起来,并用解析仪表板显示它。我已经成功地将parse server示例与parse dashboard…(通过在parse server示例/index.js和parse dashboard/parse dashboard config.json中更改appId和masterKey)链接。我已经安装了mongodb和所有东西(mongodb、解析服务器示例和解析仪表板工作得非常好) 但现在,当我试图在android项目中初始化pa

我正在尝试将一个新的android项目与解析服务器示例(本地)连接起来,并用解析仪表板显示它。我已经成功地将parse server示例与parse dashboard…(通过在parse server示例/index.js和parse dashboard/parse dashboard config.json中更改appId和masterKey)链接。我已经安装了mongodb和所有东西(mongodb、解析服务器示例和解析仪表板工作得非常好)

但现在,当我试图在android项目中初始化parse服务器时,它在本地parse中不会创建任何东西(类)。谢谢我的代码

清单文件

<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ 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.
  -->
<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="@string/parse_app_id" />
        <meta-data
            android:name="com.parse.CLIENT_KEY"
            android:value="@string/parse_client_key" />

        <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>
MainActivity.java

package com.parse.starter;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

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


public class MainActivity extends AppCompatActivity {

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

    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);
  }
}
StarterApplication.java

package com.parse.starter;

import android.app.Application;

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


public class StarterApplication extends Application {

  @Override
  public void onCreate() {
    super.onCreate();

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    // Add your initialization code here
   //Parse.initialize(this);

      Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
              .applicationId("@string/parse_app_id")
              .clientKey("@string/parse_client_key")
              .server("http://localhost:1337/parse/")   // '/' important after 'parse'
              .build());

      ParseObject testObject = new ParseObject("TestObject");
      testObject.put("foo", "bar");
      testObject.saveInBackground();


      ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.
    // defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
  }
}
我还尝试将对象的创建放在主活动中

MainActivity.java

public class MainActivity extends AppCompatActivity {

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

    ParseAnalytics.trackAppOpenedInBackground(getIntent());

    ParseObject testObject = new ParseObject("TestObject");
    testObject.put("foo", "bar");
    testObject.saveInBackground();

  }

为什么代码中有localhost?Localhost意味着请求在本地设备上运行,您可以在服务器内部使用它,但不能在客户端设备上使用。尝试将服务器/计算机的一些IP地址放在那里

.server("http://localhost:1337/parse/")

在初始化方法中,使用.server(API_地址),API地址由解析服务提供者提供。e、 g.back4app调用它的API地址

谢谢..答案..解决了!!你对ParseUser.getCurrentUser()做了什么。文档中说使用request.user,但什么是request object.what不是localhost,而是写远程设备可以远程访问的服务器的IP地址,例如10.0.0.3或192.168.1.1,您的IP地址看起来会不同。请确保删除Android清单文件中的以下行,这是因为您在Starter Application.java中使用了自定义配置
.server("http://localhost:1337/parse/")