2015-09-11 70 views
1

我剛開始使用Parse.com。試圖保存三個簡單的變量。無法保存數據,解析雲

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
     ParseObject testObject = new ParseObject("WorkTable"); 
     testObject.put("foo", "bar"); 
     testObject.put("foo1", "bar"); 
     testObject.put("fo", "bar"); 
     testObject.saveInBackground(); 
    ParseAnalytics.trackAppOpenedInBackground(getIntent()); 
    } 

用於初始化Parse和auth的類。 ###是真正的App ID和客戶端密鑰。

public class ParseApplication extends Application { 
     @Override 
     public void onCreate() { 
      super.onCreate(); 
      Parse.enableLocalDatastore(getApplicationContext()); 
      Parse.initialize(this, "###", "###"); 
     } 
    } 

在清單:

<application 
     android:name="com.parse.starter.ParseApplication" 
     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="###" /> 
     <meta-data 
      android:name="com.parse.CLIENT_KEY" 
      android:value="###" /> 

我發現這個日誌中:

09-11 11:30:32.540 23532-24173/com.parse.starter D/dalvikvm﹕ threadid=12 (ParseRequest.NETWORK_EXECUTOR-thread-24): calling run() 
09-11 11:30:32.543 23532-24173/com.parse.starter D/libc-netbsd﹕ getaddrinfo: api.parse.com NO result from proxy 
09-11 11:30:32.543 23532-24173/com.parse.starter I/System.out﹕ [CDS][DNS]Unable to resolve host "api.parse.com": No address associated with hostname 

也許它意味着什麼?

證書是正確的,檢查了十億次。 表「WorkTable」已創建,但始終爲空。 我做錯了什麼,請幫忙。

+0

我仍然說交叉驗證應用程序ID和客戶端密鑰。如果你有下面提到的配置,一切似乎都OK。 – virendrao

回答

-1

在您的應用程序的某個地方,您需要記住設置Parse提供給您的應用程序ID和密鑰。我在onCreate方法的Application對象中完成了它;

Application.java:

public void onCreate() { 
    Parse.initialize(this, "Your Application Id", "Your Client Key"); 
} 

無論你需要的然後就創建新的parseObject。

ParseObject gameScore = new ParseObject("GameScore"); 
gameScore.put("score", 1337); 
gameScore.put("playerName", "Sean Plott"); 
gameScore.put("cheatMode", false); 
gameScore.pinInBackground(); 

注意:請不要忘記指定應用程序的名稱來體現」應用標籤象下面這樣:

<application 
     android:name=".Application" 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
+0

我已經完成了所有工作。我可以在Parse的數據瀏覽器中看到這個空表,但它是空的。 –

+0

只是嘗試從清單中刪除元標記,並在解析數據庫中定義所需的列。 – KishuDroid

+0

這個答案是無益的。顯然他已經初始化了他的鑰匙。另外,使用pinInBackground用於本地數據存儲。 saveInBackground是正確的。 – Aquaballin

0
public class ParseApplication extends Application { 
    @Override 
     public void onCreate() { 
      super.onCreate(); 
      ParseCrashReporting.enable(this); 
      Parse.enableLocalDatastore(this); 
      Parse.initialize(this,"key", "key"); 
      ParseUser.enableAutomaticUser(); 
      ParseACL defaultACL = new ParseACL(); 
      defaultACL.setPublicReadAccess(true); 
      ParseACL.setDefaultACL(defaultACL, true); 
      ParseObject a = new ParseObject("a"); 
      a.put("shoe"); 
      a.saveInBackground(); 
    } 
} 

看看這個數據保存,讓我知道發生了什麼,並給予日誌