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 6747069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:51+00:00 2026-05-26T12:23:51+00:00

I am implementing a code that based upon a particular response from a web

  • 0

I am implementing a code that based upon a particular response from a web service calls the next activity in my project. I am facing some problems regarding the same as it is resulting in a NullPointerException

Here is my Android code :

           package com.example;
           import java.net.SocketException;
           import org.ksoap2.SoapEnvelope;
           import org.ksoap2.serialization.SoapObject;
           import org.ksoap2.serialization.SoapPrimitive;
           import org.ksoap2.serialization.SoapSerializationEnvelope;
           import org.ksoap2.transport.HttpTransportSE;
           import android.app.Activity; 
           import android.app.ProgressDialog;
           import android.content.Intent;
           import android.os.AsyncTask;
           import android.os.Bundle;
           import android.util.Log;
           import android.view.View; 
           import android.view.View.OnClickListener;
           import android.widget.Button;
           import android.widget.EditText;

     public class TeacherLogin2Activity extends Activity
        {
    private final String NAMESPACE = "http://tempuri.org/";
    private final String URL = "http://10.0.2.2/loginteacher/Service1.asmx";

    String t_id;
    String password;
    String ahead;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button signin = (Button) findViewById(R.id.regsubmitbtn);

            signin.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {


                            EditText etxt_user = (EditText) findViewById(R.id.usereditlog);
                            t_id = etxt_user.getText().toString();
                            EditText etxt_password = (EditText) findViewById(R.id.pwdeditlog);
                            password = etxt_password.getText().toString();


                            new LoginTask().execute();

                    }
            });   
    }

    private String doLogin(String t_id, String password) {

       String res=null;
       final String SOAP_ACTION = "http://tempuri.org/GetLogin";
       final String METHOD_NAME = "GetLogin";     
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

       request.addProperty("teacherid", t_id);
       request.addProperty("password",password);
       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
       envelope.dotNet = true; // Set this variable to true for
                                                               // compatibility with what seems to be the
                                                               // default encoding for .Net-Services.
       envelope.setOutputSoapObject(request);

       System.out.println(request);

       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


       try {
              androidHttpTransport.call(SOAP_ACTION, envelope);
              SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
              Log.i("myApp", response.toString());
              System.out.println("response" +response);
              res=response.toString(); 
              System.out.println(res);


         }catch(SocketException ex)
          {
           Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
           ex.printStackTrace();
       }
       catch (Exception e) {
           Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
               e.printStackTrace();
       }

       return res;

       }


        private class LoginTask extends AsyncTask<Void, String, String> {

        private final ProgressDialog dialog = new ProgressDialog(
                TeacherLogin2Activity.this);

        protected void onPreExecute() {

                this.dialog.setMessage("Logging in...");
                this.dialog.show();

        }


        protected String doInBackground(final Void... unused) {

            String auth=doLogin(t_id,password);
            System.out.println(auth);

            return null; // don't interact with the ui!
        }


        protected void onPostExecute(String result) 
        {

                  ahead=result;
                if(result.equals("Welcome to this activity")){
                   Intent showContent = new Intent(getApplicationContext(),newscreen.class);
                    startActivity(showContent);
                }
                if (this.dialog.isShowing()) {
                this.dialog.dismiss();
                                             }
          }

        }

         } 

updated Logcat showing Run Time Exception as well:

                10-28 19:40:00.099: ERROR/AndroidRuntime(1001): FATAL EXCEPTION: main
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001): java.lang.RuntimeException:  Unable to start activity ComponentInfo{com.example/com.example.newscreen}: java.lang.NullPointerException
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.os.Handler.dispatchMessage(Handler.java:99)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.os.Looper.loop(Looper.java:123)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.app.ActivityThread.main(ActivityThread.java:4627)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at java.lang.reflect.Method.invokeNative(Native Method)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at java.lang.reflect.Method.invoke(Method.java:521)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at dalvik.system.NativeStart.main(Native Method)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001): Caused by: java.lang.NullPointerException
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at com.example.newscreen.onCreate(newscreen.java:25)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
               10-28 19:40:00.099: ERROR/AndroidRuntime(1001):     ... 11 more

I have put all the required Internet permissions in my AndroidManifest.xml file ..Can someone help solve my problem?

  • 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-05-26T12:23:52+00:00Added an answer on May 26, 2026 at 12:23 pm

    result is coming as Null so it is throwing Null Pointer Exception , try to print result and check what is coming using Log.

    Store result in Global variable and access it inside of Asyn task.

    Eg:Declare Variable as String final_result before of Activity and store result as final_result=result

    then Compare final_result.equalsIgnoreCase("BLA BLA BLA");

    public class Articles extends Activity {
         String res=null;
         @Override
        protected void onCreate(Bundle savedInstanceState) {
           // TODO Auto-generated method stub
           super.onCreate(savedInstanceState);
           setContentView(R.layout.articles_list);
           new LoginTask().execute(t_id,password);
         }
       }
    
    public class Articles_Asyn_Task extends AsyncTask<String, Void, Void> { 
        // can use UI thread here
        protected void onPreExecute() {
            progress_dialog_async_task = ProgressDialog.show(getParent(), "Loading...","Please wait...");
        }
        @Override
        protected Void doInBackground(String... params) {
        String t_id,password;
        try{
            t_id=params[0];
            password=params[1];
        }catch(Exception e){}
    
        final String SOAP_ACTION = "http://tempuri.org/GetLogin";
       final String METHOD_NAME = "GetLogin";     
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    
       request.addProperty("teacherid", t_id);
       request.addProperty("password",password);
       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
       envelope.dotNet = true; // Set this variable to true for
                                                               // compatibility with what seems to be the
                                                               // default encoding for .Net-Services.
       envelope.setOutputSoapObject(request);
    
       System.out.println(request);
    
       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
       try {
              androidHttpTransport.call(SOAP_ACTION, envelope);
              SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
              Log.i("myApp", response.toString());
              System.out.println("response" +response);
              res=response.toString(); 
              System.out.println(res);
    
    
         }catch(SocketException ex)
          {
           Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
           ex.printStackTrace();
       }
       catch (Exception e) {
           Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
               e.printStackTrace();
       }
            return null;
        }   
        protected void onPostExecute(Void result) {
            if(res.equalsIgnoreCase("BLA BLA BLA")){
            startActivity(new Intent(Main.this,Main_1.class));
            }
    
            if (progress_dialog_async_task.isShowing()) {
                progress_dialog_async_task.dismiss();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I'm trying to write a function that calls a static function based upon
When implementing the Strategy Pattern, where does one put the code that determines which
Am having a number of problems implementing the code from the Washington Post site
implementing publishActivity in PHP using the REST API using this code: $activity = array(
I have a database that can have different types of relatinships based upon what
I am implementing a MPMediaPickerController based application. In that When I tried to open
I'm having trouble implementing a service based off of a third-party wsdl. The third-party
I have started design of a ColdFusion application that is entirely web based. Not
I am implementing a webview based application, in that I tried to load an
I am working on a 3d tile-based strategy game and have read that implementing

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.