Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:32:55+00:00 2026-06-15T22:32:55+00:00

I have a login page in my app and i have a server. whenever

  • 0

I have a login page in my app and i have a server. whenever i set my tab to connect to other wireless connection and click the login button, it outputs an error “No route to host” and crashes. but, if i connect to my server it works perfectly fine. i want to put a prompt whenever i connected to the wrong server on login.

here’s my code… but i don’t know where to put this.. pls help.

        AlertDialog.Builder builder = new AlertDialog.Builder(LoginPage.this);
        builder.setTitle("Attention!");
        builder.setMessage("Connection to Server failed.");
        builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
                new phpRequest().execute();

        }
        });
        builder.setNegativeButton("Cancel", null);

        AlertDialog dialog = builder.create();
        dialog.show();

here’s my phpRequest.

   private class phpRequest extends AsyncTask<String, Integer, String> 
{

    @Override
    protected String doInBackground(String... params) 
    {

        String responseString = "";

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost request = new HttpPost(myurl);

        try
        {    
            String studSt = etStudNo.getText().toString();
            String passSt = etPassword.getText().toString();

            List<NameValuePair> parameter = new ArrayList<NameValuePair>();
            parameter.add(new BasicNameValuePair("student_id", studSt));
            parameter.add(new BasicNameValuePair("password", passSt));

            request.setEntity(new UrlEncodedFormEntity(parameter));

            HttpResponse response = httpclient.execute(request);
            StatusLine statusLine = response.getStatusLine(); 



            if(statusLine.getStatusCode() == HttpStatus.SC_OK)
            {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                responseString = out.toString();                       
            }
            else
            {

                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }

        }
        catch (Exception ioe)
        {

            Log.e("Error", ioe.toString());
        }



        return responseString;
    }

     @Override
     protected void onPostExecute(String result) 
     {      
         super.onPostExecute(result);
         String c = result;
         int check = Integer.parseInt(c);

         if (check == 1)
         {
             Intent i = new Intent(LoginPage.this,HomePage.class);
             startActivity(i); 

             globalVars globalVars = (globalVars)getApplicationContext();

                String idnumber = etStudNo.getText().toString();
                globalVars.setStudLoggedId(idnumber);               

             Toast.makeText(getBaseContext(), "Student No: "+etStudNo.getText().toString(),Toast.LENGTH_LONG).show();
         }
         else
         {
             etPassword.setText("");
             Toast.makeText(getBaseContext(), "Login Failed", Toast.LENGTH_LONG).show(); 
         }
     }
}    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:32:56+00:00Added an answer on June 15, 2026 at 10:32 pm

    The problem starts here:

    HttpResponse response = httpclient.execute(request);
    

    as this is going to throw an IOException if it can’t connect to the server and complete the request.

    You then catch the exception here:

    catch (Exception ioe)
    {
        Log.e("Error", ioe.toString());
    }
    

    and your function continues, but responseString still contains the empty string “” that you first assigned to it, not the HTTP response (as it never completed).

    This means the empty string “” gets returned and passed to onPostExecute(String result), where Integer.parseInt(c) will fail and throw a NumberFormatException which is probably what is crashing your app.

    A simple solution would be:

    1. Inside the exception handler in doInBackground(), after logging the error you should return null to indicate the method failed.
    2. Then inside onPostExecute(String result), check if result is null before doing anything else. If it is, you know the request failed and you can safely pop up a dialog box describing the error.

    If you put a few breakpoints into Eclipse you can follow this through yourself and understand it properly.

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app needs to have multiple screen e.g. one login page then another page
I have Page Tab App, which has a landing page with a Log In
Normally we have login page with username, password filed and signin button. Using the
I have a login page written in classic asp. I want to set the
I have created an app which starts with a login page, after entering some
I have a silverlight app that uses a simple Login.aspx page. I have all
I have a web app that is being hit by facebook. The login page
I have a login page (an activity in Android), during which I run an
I have a Login page that captures User input like this. MD5calc ss =
I have created login page forced login in several pages. Now i need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.