0

Good day,

At this moment i'm having a issue with the connection with Parse. The application we are working at is at this moment connecting towards the DB of Parse. But when going back towards the main menu and then back towards the same page where the database connection is, it crashes.

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.
        }
    }
}

Error log:

    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
RaWolfe
  • 1
  • 3
  • Use Asynctask http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception – kgandroid May 20 '14 at 06:48
  • No offends, but this does not quite help me with the problem. The problem from the other page is about a RSS feed and this is about a connection problem with the reconnecting database. – RaWolfe May 20 '14 at 12:37
  • you are accessing http/parse on the main thread. Get your access to parse and to http api OFF the main thread using asyncTask or Handler Callbacks. – Robert Rowntree May 20 '14 at 14:35

0 Answers0