Q:

Java on Android using Android Studio

The program I have is just crashing the emulator and says:

Unfortunately "program name here" has stopped working.

Below is the Java and XML. It compiles okay.
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;

public class IconCMOLogin extends ActionBarActivity {

EditText phlogin,pword,uname;
Button btnSubmit;
String finalstring;
String chp, unm, psw;
Button btn;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_icon_cmologin);

        phlogin = (EditText)findViewById(R.id.phlogin);
        uname = (EditText)findViewById(R.id.uname);
        pword = (EditText)findViewById(R.id.pword);
        chp = phlogin.getText().toString();
        unm = uname.getText().toString();
        psw = pword.getText().toString();
        btn = (Button)findViewById(R.id.btnsubmit);

    btnSubmit.setOnClickListener(new OnClickListener()
     {
        @Override
        public void onClick(View v) {
            finalstring = "https://app.iconcmo.com/index.asp?action=login&phone=chp&username=unm&password=psw";
            Toast.makeText(IconCMOLogin.this, finalstring,
                    Toast.LENGTH_SHORT).show();
        }
     });

    }

}

XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".IconCMOLogin"
    >

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/pword"
        android:hint="Your Password"
        android:layout_below="@+id/uname"
        android:layout_alignLeft="@+id/uname"
        android:layout_alignStart="@+id/uname"
        android:layout_marginTop="76dp" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Submit"
        android:id="@+id/btnsubmit"
        android:layout_alignParentBottom="true"
        android:layout_alignLeft="@+id/pword"
        android:layout_alignStart="@+id/pword" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:ems="10"
        android:id="@+id/phlogin"
        android:text="Phone"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="83dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="Name"
        android:ems="10"
        android:id="@+id/uname"
        android:layout_below="@+id/phlogin"
        android:layout_alignLeft="@+id/phlogin"
        android:layout_alignStart="@+id/phlogin"
        android:layout_marginTop="46dp" />

</RelativeLayout>

A:

You are assigning OnClickListener to the object that hasn't been initialized. Thus, you receive a NullPointerException. Replace the line
btn = (Button)findViewById(R.id.btnsubmit);

with
btnSubmit = (Button)findViewById(R.id.btnsubmit);

And I suppose everything will work. But just not for the future, whenever your app crashes, please attach the stack trace of the exception

