1

I am just trying to run a simple test on my "hello world" programme in android studio , the programme is below:

package com.example.gautam.droidone.tests;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;

import com.example.gautam.droidone.MainActivity;
import com.example.gautam.droidone.R;
import android.util.Log;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {

    MainActivity activity;

    public MainActivityTest() {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
    }

    public void testMainActivity() {
            TextView textView = (TextView) activity.findViewById(R.id.hello_world);
            Log.d("MainActivityTest", textView.getText().toString());
        assertNotNull(textView);
    }
}

When i click on the debug button, i get the following error in the console:

Error running MainActivityTest: Unable to open debugger port (127.0.0.1:58061): java.net.SocketException "socket closed". 

Similar so threads:

Thread 1 Thread 2 Thread 3

I googled the error and found a few solutions to the problem, most of them did't work, then i saw THIS article and in the comments section a few people have suggested that you need to turn off build-process. how do you do that , on reading more on google , i found that since android 1+ this option is no longer available , so how do i turn off build process ? and once again why am i getting this error:

Error running MainActivityTest: Unable to open debugger port (127.0.0.1:58061): java.net.SocketException "socket closed"

Community
  • 1
  • 1
Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174

1 Answers1

4

I had the same problem. My fault that in the tool bar the wrong target was selected. It has to be "App". It can easily been selected wrong with a single unintended mouseclick. So check if there is "App" or something like "assemble".

Lawi
  • 86
  • 2