title: performing login to my university student portal via app
body: <p>I wanted to connect to the student portal of my university with my app and access certain information from the website like the current result. so I have written this code so far I am having trouble logging in. Whenever I pressed login button the app crashes.. I know something is wrong with my code so I will be really thankful if you guys help me fix the problem.. here is the url of the my student profile.</p>
  
  <p><a href="http://111.68.99.8/StudentProfile/" rel="nofollow">http://111.68.99.8/StudentProfile/</a></p>
  
  <p>and here is the code which I have written so far....</p>
  
  <p>java file</p>
  
  <pre><code>package com.example.ebad.testing;
  
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.UnsupportedEncodingException;
  import java.util.ArrayList;
  import java.util.List;
  
  
  public class MainActivity extends ActionBarActivity {
  
      Button login;
      TextView Enrollement,password,E;
  
  
  
      private static final String TAG = "MyActivity";
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Enrollement = (TextView) findViewById(R.id.Enrollment);
          password = (TextView) findViewById(R.id.password);
          login = (Button) findViewById(R.id.login_button);
          E = (TextView) findViewById(R.id.message);
  
          login.setOnClickListener(
                  new Button.OnClickListener() {
                      public void onClick(View v) {
  
                          String GMAIL_CONTACTS = "http://111.68.99.8/StudentProfile/PersonalInfo.aspx";
                          String GMAIL_LOGIN = "http://111.68.99.8/StudentProfile/";
                          String message_e = E.toString();
                          message_e += "";
  
                          String Enrollement_e = Enrollement.toString();
                          String password_e  = password.toString();
  
                          DefaultHttpClient httpClient = new DefaultHttpClient();
                          HttpPost httpPost = new HttpPost(GMAIL_LOGIN);
  
                          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(3);
                          nameValuePairs.add(new BasicNameValuePair("ctl00_Body_ENROLLMENTTextBox_tb", Enrollement_e));
                          nameValuePairs.add(new BasicNameValuePair("ctl00_Body_PasswordTextBox_tb", password_e));
                          nameValuePairs.add(new BasicNameValuePair("ctl00_Body_LoginButton", "login"));
  
                          try {
                              httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                          } catch (UnsupportedEncodingException e) {
                              e.printStackTrace();
                          }
  
                          // Execute HTTP Post Request
                          HttpResponse response = null;
                          try {
                              response = httpClient.execute(httpPost);
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                          message_e +=response.getStatusLine();
                          E.setText(message_e);
  
                          Log.d(TAG, "response stat code " + response.getStatusLine().getStatusCode());
  
                          if (response.getStatusLine().getStatusCode() &lt; 400) {
  
                              String cookie = response.getFirstHeader("Set-Cookie")
                                      .getValue();
                              Log.d(TAG, "cookie: " + cookie);
  
                              // get the contacts page
                              HttpGet getContacts = new HttpGet(GMAIL_CONTACTS);
                              getContacts.setHeader("Cookie", cookie);
                              try {
                                  response = httpClient.execute(getContacts);
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
  
                              InputStream ins = null;
                              try {
                                  ins = response.getEntity().getContent();
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
                              BufferedReader in = new BufferedReader(new InputStreamReader(
                                      ins));
  
                              String inputLine;
                              try {
                                  while ((inputLine = in.readLine()) != null) {
                                      Log.d(TAG, " " + inputLine);
                                  }
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
  
                              try {
                                  in.close();
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
                          } else {
                              Log.d(TAG, "Response error: "
                                      + response.getStatusLine().getStatusCode());
                          }
  
  
                      }
                  }
          );
  
  
      }
  
  
  
  
  
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>and this is the xml file...</p>
  
  <pre><code>&lt;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=".MainActivity"&gt;
  
  
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="Enter the Enrollement"
          android:id="@+id/Enrollment"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="51dp"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true" /&gt;
  
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/password"
          android:hint="Enter the Password"
          android:layout_marginTop="50dp"
          android:layout_below="@+id/Enrollment"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="LOGIN"
          android:id="@+id/login_button"
          android:layout_centerVertical="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true"
          android:layout_marginRight="38dp"
          android:layout_marginEnd="38dp" /&gt;
  
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/message"
          android:layout_below="@+id/login_button"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_marginTop="82dp" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Logcat is here</p>
  
  <pre><code>08-06 00:43:58.542    1904-1904/com.example.ebad.testing I/art﹕ Not late-enabling -Xcheck:jni (already on)
  08-06 00:44:03.139    1904-1936/com.example.ebad.testing D/OpenGLRenderer﹕ Render dirty regions requested: true
  08-06 00:44:03.142    1904-1904/com.example.ebad.testing D/﹕ HostConnection::get() New Host Connection established 0xa6c42500, tid 1904
  08-06 00:44:03.203    1904-1904/com.example.ebad.testing D/Atlas﹕ Validating map...
  08-06 00:44:03.473    1904-1917/com.example.ebad.testing I/art﹕ Background sticky concurrent mark sweep GC freed 3295(250KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 872KB/1135KB, paused 39.997ms total 200.658ms
  08-06 00:44:03.539    1904-1917/com.example.ebad.testing W/art﹕ Suspending all threads took: 66.163ms
  08-06 00:44:03.821    1904-1911/com.example.ebad.testing W/art﹕ Suspending all threads took: 210.005ms
  08-06 00:44:03.832    1904-1936/com.example.ebad.testing D/﹕ HostConnection::get() New Host Connection established 0xa6c42a30, tid 1936
  08-06 00:44:03.838    1904-1917/com.example.ebad.testing I/art﹕ Background partial concurrent mark sweep GC freed 1888(102KB) AllocSpace objects, 0(0B) LOS objects, 55% free, 834KB/1858KB, paused 3.470ms total 295.680ms
  08-06 00:44:03.892    1904-1936/com.example.ebad.testing I/OpenGLRenderer﹕ Initialized EGL, version 1.4
  08-06 00:44:03.932    1904-1936/com.example.ebad.testing D/OpenGLRenderer﹕ Enabling debug mode 0
  08-06 00:44:03.959    1904-1936/com.example.ebad.testing W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  08-06 00:44:03.959    1904-1936/com.example.ebad.testing W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae1de500, error=EGL_SUCCESS
  08-06 00:44:03.970    1904-1917/com.example.ebad.testing W/art﹕ Suspending all threads took: 132.060ms
  08-06 00:44:04.215    1904-1904/com.example.ebad.testing I/Choreographer﹕ Skipped 38 frames!  The application may be doing too much work on its main thread.
  08-06 00:44:04.823    1904-1904/com.example.ebad.testing I/Choreographer﹕ Skipped 36 frames!  The application may be doing too much work on its main thread.
  08-06 00:44:05.503    1904-1936/com.example.ebad.testing W/EGL_emulation﹕ eglSurfaceAttrib not implemented
  08-06 00:44:05.503    1904-1936/com.example.ebad.testing W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae1de500, error=EGL_SUCCESS
  08-06 00:44:24.394    1904-1911/com.example.ebad.testing W/art﹕ Suspending all threads took: 5.553ms
  08-06 00:45:10.805    1904-1904/com.example.ebad.testing W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://111.68.99.8 refused
  08-06 00:45:10.805    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
  08-06 00:45:10.805    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  08-06 00:45:10.805    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  08-06 00:45:10.805    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
  08-06 00:45:10.805    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at com.example.ebad.testing.MainActivity$1.onClick(MainActivity.java:82)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at android.view.View.performClick(View.java:4756)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at android.view.View$PerformClick.run(View.java:19749)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  08-06 00:45:10.806    1904-1904/com.example.ebad.testing W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ Caused by: java.net.ConnectException: socket failed: EACCES (Permission denied)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:181)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ ... 17 more
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ Caused by: java.net.SocketException: socket failed: EACCES (Permission denied)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:623)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ at java.net.Socket.checkOpenAndCreate(Socket.java:687)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ at java.net.Socket.connect(Socket.java:847)
  08-06 00:45:10.807    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ ... 17 more
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.Posix.socket(Native Method)
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:608)
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing W/System.err﹕ ... 22 more
  08-06 00:45:10.808    1904-1904/com.example.ebad.testing D/AndroidRuntime﹕ Shutting down VM
      --------- beginning of crash
  08-06 00:45:10.809    1904-1904/com.example.ebad.testing E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.example.ebad.testing, PID: 1904
      java.lang.NullPointerException: Attempt to invoke interface method 'org.apache.http.StatusLine org.apache.http.HttpResponse.getStatusLine()' on a null object reference
              at com.example.ebad.testing.MainActivity$1.onClick(MainActivity.java:86)
              at android.view.View.performClick(View.java:4756)
              at android.view.View$PerformClick.run(View.java:19749)
              at android.os.Handler.handleCallback(Handler.java:739)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  08-06 00:45:13.333    1904-1904/com.example.ebad.testing I/Process﹕ Sending signal. PID: 1904 SIG: 9
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.ebad.testing" &gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>