Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
空对象引用android聊天应用程序上的java.lang.NullPointerException_Java_Android_Nullpointerexception_Chat - Fatal编程技术网

空对象引用android聊天应用程序上的java.lang.NullPointerException

空对象引用android聊天应用程序上的java.lang.NullPointerException,java,android,nullpointerexception,chat,Java,Android,Nullpointerexception,Chat,我正在为Androdid创建聊天应用程序。错误是当我运行注册活动时,我得到了java.lang.nullpointerExecption错误,我无法解决此错误。这是我的叹息 错误:` 流程:com.example.hazziq.slidechat,PID:2106 java.lang.NullPointerException:尝试对空对象引用调用接口方法“java.lang.String com.exmaple.hazziq.slidechat.interface.Manager.signUpU

我正在为Androdid创建聊天应用程序。错误是当我运行注册活动时,我得到了java.lang.nullpointerExecption错误,我无法解决此错误。这是我的叹息

错误:`

流程:com.example.hazziq.slidechat,PID:2106 java.lang.NullPointerException:尝试对空对象引用调用接口方法“java.lang.String com.exmaple.hazziq.slidechat.interface.Manager.signUpUser(java.lang.String,java.lang.String,java.lang.String)” 位于com.example.hazziq.slidechat.SigningUp$2$1.run(SigningUp.java:107)

错误行:

result = imService.signUpUser(usernameText.getText().toString(),
                                            passwordText.getText().toString(),
                                            eMailText.getText().toString());

android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.example.hazziq.slidechat.serve.MessagingService;
import com.exmaple.hazziq.slidechat.interfacer.Manager;


public class SigningUp extends Activity {

    private static final int FILL_ALL_FIELDS = 0;
    protected static final int TYPE_SAME_PASSWORD_IN_PASSWORD_FIELDS = 1;
    private static final int SIGN_UP_FAILED = 9;
    private static final int SIGN_UP_USERNAME_CRASHED = 3;
    private static final int SIGN_UP_SUCCESSFULL = 4;
    protected static final int USERNAME_AND_PASSWORD_LENGTH_SHORT = 5;


    //private static final String SERVER_RES_SIGN_UP_FAILED = "0";
    private static final String SERVER_RES_RES_SIGN_UP_SUCCESFULL = "1";
    private static final String SERVER_RES_SIGN_UP_USERNAME_CRASHED = "2";



    private EditText usernameText;
    private EditText passwordText;
    private EditText eMailText;
    private EditText passwordAgainText;
    private Manager imService;
    private Handler handler = new Handler();

    private ServiceConnection mConnection = new ServiceConnection() {


        public void onServiceConnected(ComponentName className, IBinder service) {
            // This is called when the connection with the service has been
            // established, giving us the service object we can use to
            // interact with the service.  Because we have bound to a explicit
            // service that we know is running in our own process, we can
            // cast its IBinder to a concrete class and directly access it.
            imService = ((MessagingService.IMBinder)service).getService();


        }

        public void onServiceDisconnected(ComponentName className) {
            // This is called when the connection with the service has been
            // unexpectedly disconnected -- that is, its process crashed.
            // Because it is running in our same process, we should never
            // see this happen.
            imService = null;
            Toast.makeText(SigningUp.this, R.string.local_service_stopped,
                    Toast.LENGTH_SHORT).show();
        }
    };

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        setContentView(R.layout.activity_signing_up);
        setTitle("Sign up");

        Button signUpButton = (Button) findViewById(R.id.signUp);
        Button cancelButton = (Button) findViewById(R.id.cancel_signUp);
        usernameText = (EditText) findViewById(R.id.userName);
        passwordText = (EditText) findViewById(R.id.password);
        passwordAgainText = (EditText) findViewById(R.id.passwordAgain);
        eMailText = (EditText) findViewById(R.id.email);

        signUpButton.setOnClickListener(new OnClickListener(){
            public void onClick(View arg)
            {
                if (usernameText.length() > 0&&
                        passwordText.length() > 0 &&
                        passwordAgainText.length() > 0 &&
                        eMailText.length() > 0
                        )
                {
                    //TODO check email address is valid

                    if (passwordText.getText().toString().equals(passwordAgainText.getText().toString())){

                        if (usernameText.length() >= 5 && passwordText.length() >= 5) {

                            Thread thread = new Thread(){
                                String result = new String();

                                @Override
                                public void run() {

                             result = imService.signUpUser(usernameText.getText().toString(),
                                            passwordText.getText().toString(),
                                            eMailText.getText().toString());

                                    handler.post(new Runnable(){

                                        public void run() {
                                            if (result!= null && equals(SERVER_RES_RES_SIGN_UP_SUCCESFULL)) {
                                                Toast.makeText(getApplicationContext(),R.string.signup_successfull, Toast.LENGTH_LONG).show();

                                            }
                                            else if (result.equals(SERVER_RES_SIGN_UP_USERNAME_CRASHED)){

                                                Toast.makeText(getApplicationContext(),R.string.signup_username_crashed, Toast.LENGTH_LONG).show();
                                              ;
                                            }
                                            else  //if (result.equals(SERVER_RES_SIGN_UP_FAILED))
                                            {
                                                Toast.makeText(getApplicationContext(),R.string.signup_failed, Toast.LENGTH_LONG).show();
                                                //showDialog(SIGN_UP_FAILED);
                                            }
                                        }

                                    });
                                }

                            };
                            thread.start();
                        }
                        else{
                            Toast.makeText(getApplicationContext(),R.string.username_and_password_length_short, Toast.LENGTH_LONG).show();
                            //showDialog(USERNAME_AND_PASSWORD_LENGTH_SHORT);
                        }
                    }
                    else {
                        Toast.makeText(getApplicationContext(),R.string.signup_type_same_password_in_password_fields, Toast.LENGTH_LONG).show();
                        //showDialog(TYPE_SAME_PASSWORD_IN_PASSWORD_FIELDS);
                    }

                }
                else {
                    Toast.makeText(getApplicationContext(),R.string.signup_fill_all_fields, Toast.LENGTH_LONG).show();
                    //showDialog(FILL_ALL_FIELDS);

                }
            }
        });

        cancelButton.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0)
            {
                finish();
            }
        });


    }


    protected Dialog onCreateDialog(int id)
    {

        switch (id)
        {
            case TYPE_SAME_PASSWORD_IN_PASSWORD_FIELDS:
                return new AlertDialog.Builder(SigningUp.this)
                        .setMessage(R.string.signup_type_same_password_in_password_fields)
                        .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                        /* User clicked OK so do some stuff */
                            }
                        })
                        .create();
            case FILL_ALL_FIELDS:
                return new AlertDialog.Builder(SigningUp.this)
                        .setMessage(R.string.signup_fill_all_fields)
                        .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                        /* User clicked OK so do some stuff */
                            }
                        })
                        .create();
            case SIGN_UP_FAILED:
                return new AlertDialog.Builder(SigningUp.this)
                        .setMessage(R.string.signup_failed)
                        .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                        /* User clicked OK so do some stuff */
                            }
                        })
                        .create();
            case SIGN_UP_USERNAME_CRASHED:
                return new AlertDialog.Builder(SigningUp.this)
                        .setMessage(R.string.signup_username_crashed)
                        .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                        /* User clicked OK so do some stuff */
                            }
                        })
                        .create();
            case SIGN_UP_SUCCESSFULL:
                return new AlertDialog.Builder(SigningUp.this)
                        .setMessage(R.string.signup_successfull)
                        .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                finish();
                            }
                        })
                        .create();
            case USERNAME_AND_PASSWORD_LENGTH_SHORT:
                return new AlertDialog.Builder(SigningUp.this)
                        .setMessage(R.string.username_and_password_length_short)
                        .setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                        /* User clicked OK so do some stuff */
                            }
                        })
                        .create();
            default:
                return null;

        }


    }

    @Override
    protected void onResume() {
        bindService(new Intent(SigningUp.this, MessagingService.class), mConnection , Context.BIND_AUTO_CREATE);

        super.onResume();
    }

    @Override
    protected void onPause()
    {
        unbindService(mConnection);
        super.onPause();
    }
}

请帮助p我陷入此错误很长时间。

您必须检查您的EditText是否为空。大概是这样的:

if(usernameText != null && passwordText != null && eMailText != null) {
   if(!TextUtils.isEmpty(usernameText.getText()) && !TextUtils.isEmpty(passwordText.getText()) && 
      !TextUtils.isEmpty(eMailText.getText()) {
       result = imService.signUpUser(usernameText.getText().toString(),
                                        passwordText.getText().toString(),
                                        eMailText.getText().toString());
   } else {
       // ask user to fill all required fields
   }
}

为了能帮助你,你不需要帮助我们。请阅读Iv完成您告诉我的操作://TODO检查电子邮件地址是否有效如果(usernameText!=null&&passwordText!=null&&eMailText!=null){if(!TextUtils.isEmpty(usernameText.getText())&&&!TextUtils.isEmpty(passwordText.getText())&&&!TextUtils.isEmpty(eMailText.getText()){Thread Thread=new Thread(){String result=new String();但我仍然收到相同的错误。。。。。