解析连接不会连接第二次

时间:2014-05-20 06:46:08

标签: android connection parse-platform

美好的一天,

此刻我遇到与Parse连接的问题。 我们正在处理的应用程序正在连接到Parse的DB。 但是当回到主菜单然后回到数据库连接所在的同一页面时,它会崩溃。

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

public class Clothing extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clothing);//database connection
        Parse.initialize(this, "DBinfo removed", "Password DB removed");

        final TextView t = (TextView) findViewById(R.id.textView1);

        {
            ParseQuery<ParseObject> query = ParseQuery.getQuery("Products");
            query.whereEqualTo("objectId", "5nVfgKvqkM");
            query.findInBackground(new FindCallback<ParseObject>() {
            @Override
              public void done(List<ParseObject> objects, ParseException e) {
                  try {
                      e.equals(null);
                      System.out.println("bug");
                  } 
                  catch (NullPointerException ex){
                    System.out.println("size of list is  " + objects.size());

                    t.setText(objects.get(0).toString());
                  }

              }
          });

          // Now don't use query again.
        }
    }
}

错误日志:

    05-19 14:45:34.806: W/dalvikvm(570): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
05-19 14:45:34.855: E/AndroidRuntime(570): FATAL EXCEPTION: main
05-19 14:45:34.855: E/AndroidRuntime(570): java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.creationinc.swopp2/nl.creationinc.swopp2.Clothing}: android.os.NetworkOnMainThreadException
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.os.Looper.loop(Looper.java:137)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.ActivityThread.main(ActivityThread.java:4340)
05-19 14:45:34.855: E/AndroidRuntime(570):  at java.lang.reflect.Method.invokeNative(Native Method)
05-19 14:45:34.855: E/AndroidRuntime(570):  at java.lang.reflect.Method.invoke(Method.java:511)
05-19 14:45:34.855: E/AndroidRuntime(570):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-19 14:45:34.855: E/AndroidRuntime(570):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-19 14:45:34.855: E/AndroidRuntime(570):  at dalvik.system.NativeStart.main(Native Method)
05-19 14:45:34.855: E/AndroidRuntime(570): Caused by: android.os.NetworkOnMainThreadException
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.close(OpenSSLSocketImpl.java:922)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.http.impl.SocketHttpClientConnection.close(SocketHttpClientConnection.java:205)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.http.impl.conn.DefaultClientConnection.close(DefaultClientConnection.java:161)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.http.impl.conn.tsccm.AbstractConnPool.closeConnection(AbstractConnPool.java:320)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.http.impl.conn.tsccm.AbstractConnPool.shutdown(AbstractConnPool.java:296)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.shutdown(ConnPoolByRoute.java:670)
05-19 14:45:34.855: E/AndroidRuntime(570):  at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.shutdown(ThreadSafeClientConnManager.java:257)
05-19 14:45:34.855: E/AndroidRuntime(570):  at com.parse.ParseRequest.initialize(ParseRequest.java:118)
05-19 14:45:34.855: E/AndroidRuntime(570):  at com.parse.Parse.initialize(Parse.java:109)
05-19 14:45:34.855: E/AndroidRuntime(570):  at nl.creationinc.swopp2.Clothing.onCreate(Clothing.java:21)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.Activity.performCreate(Activity.java:4465)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-19 14:45:34.855: E/AndroidRuntime(570):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
05-19 14:45:34.855: E/AndroidRuntime(570):  ... 11 more
05-19 14:45:35.406: D/dalvikvm(570): GC_CONCURRENT freed 335K, 7% free 7387K/7879K, paused 7ms+39ms

0 个答案:

没有答案