I'm trying to write a messaging application, but when I start it, it crashes, and I do not get an error message, so I have no clue why.
Launch Activity:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.*;
public class ConnectActivity extends AppCompatActivity {
private Client client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final EditText txtServerAddress = (EditText) findViewById(R.id.edit_text_server_address);
final EditText txtPortNumber = (EditText) findViewById(R.id.edit_text_port_number);
final EditText txtUsername = (EditText) findViewById(R.id.edit_text_username);
final Button btnLogIn = (Button) findViewById(R.id.button_log_in);
btnLogIn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String username = txtUsername.getText().toString();
if(username.length() == 0)
return;
String portNumber = txtPortNumber.getText().toString();
if(portNumber.length() == 0)
return;
String serverAddress = txtServerAddress.getText().toString();
if(serverAddress.length() == 0)
return;
int port = 0;
try
{
port = Integer.parseInt(portNumber);
}
catch(Exception en)
{
return;
}
ClientActivity clientActivity = new ClientActivity(client);
client = new Client(serverAddress, port, username, clientActivity);
if(!client.start())
return;
Intent intent = new Intent(ConnectActivity.this, ClientActivity.class);
startActivity(intent);
}
});
setContentView(R.layout.activity_connect);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
Launch Content xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.liftedstarfish.lifte.gpschat0_2.ConnectActivity"
tools:showIn="@layout/activity_connect">
<TextView
android:id="@+id/text_view_server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/server_address"
android:textColor="@android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_port_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/port_number"
android:textColor="@android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_text_server_address" />
<TextView
android:id="@+id/text_view_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/username"
android:textColor="@android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_text_port_number" />
<EditText
android:id="@+id/edit_text_server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName|numberDecimal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_server_address" />
<EditText
android:id="@+id/edit_text_port_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_port_number" />
<EditText
android:id="@+id/edit_text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_username" />
<Button
android:id="@+id/button_log_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="@string/log_in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Launch Activity xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.liftedstarfish.lifte.gpschat0_2.ConnectActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_connect" />
</android.support.design.widget.CoordinatorLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liftedstarfish.lifte.gpschat0_2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ClientActivity"
android:label="@string/title_activity_client"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ConnectActivity"
android:label="@string/title_activity_connect"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
As far as I can tell, I've done everything correctly, but the application is still crashes. I've tried cleaning the application and rebuilding it, but that did not help.