So I'm creating a simple android app that will connect to a java server I created that can send text messages to and from the server. I am trying to get the android app to connect to the server and I am having no luck. Right now I have hard coded the IP address into the app, but I will eventually have a dialog where the user enters the IP address.

Right now I am getting the error message, "Only the original thread that created a view hierarchy can touch its views.

I understand what the means I just don't know how to arrange my code and threads.

Here's my server app

Java Code:
public class Server extends JFrame {

	private JTextField enterField;
	private JTextArea displayArea;
	private ObjectOutputStream output;
	private ObjectInputStream input;
	private ServerSocket server;
	private Socket connection;
	private int counter = 1;

	public Server() {
		super ("Server");
		enterField = new JTextField();
		enterField.setEditable(true);
		enterField.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent event) {
				sendData(event.getActionCommand());
				enterField.setText("");

			}
		});
		
		add(enterField, BorderLayout.NORTH);
		displayArea = new JTextArea();
		add (new JScrollPane(displayArea));
		
		setSize(300,150);
		setVisible(true);
	}
	
	

	public void runServer() {
		try {
			server = new ServerSocket(50499, 100);
			//displayMessage("\n Listening on Port: " + server.getLocalPort() + "\n");

			while (true) {
				try {
					waitForCommunication();
					getStreams();
					processConnection();
				} catch (EOFException eofException) {
					displayMessage("\n Server terminated connection ");
				} finally {
					closeConnection();
					++counter;
				}
			}
		} catch (IOException ioException) {
			ioException.printStackTrace();
		}
	}

	private void closeConnection() {
		displayMessage("\nTerminating connection\n");
		setTextFieldEditable(false);
		try {
			output.close();
			input.close();
			connection.close();
		} catch (IOException ioException) {
			ioException.printStackTrace();
		}

	}

	private void displayMessage(final String string) {
		SwingUtilities.invokeLater(new Runnable(){

			@Override
			public void run() {
				displayArea.append(string);
			}
			
		});

	}

	private void processConnection() throws IOException {
		String message = "Connection Sucessful";
		sendData(message);

		setTextFieldEditable(true);

		do {
			try {
				message = (String) input.readObject();
				displayMessage("\n" + message);
			} catch (ClassNotFoundException classNotFoundException) {
				displayMessage("\nUnknown object type recieved");
			}
		} while (!message.endsWith(">>> TERMINATE"));
	}

	private void setTextFieldEditable(final boolean editable) {
		SwingUtilities.invokeLater(new Runnable(){

			@Override
			public void run() {
				enterField.setEditable(editable);
				
			}
			
		});

	}

	private void getStreams() throws IOException {
		output = new ObjectOutputStream(connection.getOutputStream());
		output.flush();

		input = new ObjectInputStream(connection.getInputStream());

		displayMessage("\nGOt I/O stream \n");

	}

	private void waitForCommunication() throws IOException {
		displayMessage("Waiting for cennection \n");
		connection = (server.accept());
		displayMessage("Connection" + counter + " received from: "
				+ connection.getInetAddress().getHostName());
	}

	private void sendData(String message) {
		try {
			output.writeObject("SERVER>>> " + message);
			output.flush();
			displayMessage("\nSERVER>>> " + message);
		} catch (IOException ioException){
			displayArea.append("\nError Writing Object");
		}
	}
}
Here's my android classes

Java Code:
public class Connection extends Thread {

	private Socket client;
	private ObjectOutputStream output;
	private ObjectInputStream input;
	private MainActivity mainActivity;

	public Connection(MainActivity mainActivity) {
		this.mainActivity = mainActivity;

	}

	public void connectToServer() {
		try {
			
			mainActivity.displayMessage("Connecting to server");

			client = new Socket("192.168.1.102", 50499);
			
			mainActivity.displayMessage("Connected to: "
					+ client.getInetAddress().getHostName());
			

		} catch (IOException ioException) {
			ioException.printStackTrace();
			mainActivity.displayMessage("Problem Connecting to Server");
		}
	}
Java Code:
public class MainActivity extends Activity {
	
	private Connection serverConnection;
	private ArrayList<String> listItems = new ArrayList<String>();
	private ArrayAdapter<String> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		IpEntryActivity.postHost = new Handler(){
			public void handleMessage(Message message){
				Thread connectThread = new Thread(new Runnable(){
					@Override
					public void run() {
						serverConnection = new Connection(MainActivity.this);
						serverConnection.connectToServer();
					}
					
				});
				connectThread.start();
			}
		};
		
		startActivity(new Intent(MainActivity.this, IpEntryActivity.class));
		
		runOnUiThread(new Runnable() {
		     public void run() {

		    	ListView listview = (ListView) findViewById(R.id.list);
		 		adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, listItems);
		 		listview.setAdapter(adapter);
		    }
		});
			}

	private void getIPDialog() {
		// TODO Auto-generated method stub
		
	}
	public void displayMessage(String string) {
		 listItems.add(string);
		 adapter.notifyDataSetChanged();		
	}
}
Java Code:
public class IpEntryActivity extends Activity {
	
	private static String host;
	static Handler postHost;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_ip_entry);
		
		Button submitButton = (Button) findViewById(R.id.submit_button);
		final EditText ipAddressField = (EditText) findViewById(R.id.ip_address_field);
		
		submitButton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				host = ipAddressField.getText().toString();
				postHost.sendEmptyMessage(0);
				finish();
			}

		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.ip_entry, menu);
		return true;
	}

}