11-24 02:55:16.074: E / AndroidRuntime (1164): java.lang.ArrayIndexOutOfBoundsException: length = 1; index = 1
11-24 02:55:16.074: E / AndroidRuntime (1164): at com.amaker.wlo.LoginActivity.saveUserMsg (LoginActivity.java: 88)
11-24 02:55:16.074: E / AndroidRuntime (1164): at com.amaker.wlo.LoginActivity.login (LoginActivity.java: 71)
11-24 02:55:16.074: E / AndroidRuntime (1164): at com.amaker.wlo.LoginActivity.access $ 2 (LoginActivity.java: 61)
11-24 02:55:16.074: E / AndroidRuntime (1164): at com.amaker.wlo.LoginActivity $ 2.onClick (LoginActivity.java: 50)
11-24 02:55:16.074: E / AndroidRuntime (1164): at android.view.View.performClick (View.java: 4424)
11-24 02:55:16.074: E / AndroidRuntime (1164): at android.view.View $ PerformClick.run (View.java: 18383)
11-24 02:55:16.074: E / AndroidRuntime (1164): at android.os.Handler.handleCallback (Handler.java: 733)
11-24 02:55:16.074: E / AndroidRuntime (1164): at android.os.Handler.dispatchMessage (Handler.java: 95)
11-24 02:55:16.074: E / AndroidRuntime (1164): at android.os.Looper.loop (Looper.java: 137)
11-24 02:55:16.074: E / AndroidRuntime (1164): at android.app.ActivityThread.main (ActivityThread.java: 4998)
11-24 02:55:16.074: E / AndroidRuntime (1164): at java.lang.reflect.Method.invokeNative (Native Method)
11-24 02:55:16.074: E / AndroidRuntime (1164): at java.lang.reflect.Method.invoke (Method.java: 515)
11-24 02:55:16.074: E / AndroidRuntime (1164): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 777)
11-24 02:55:16.074: E / AndroidRuntime (1164): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 593)
11-24 02:55:16.074: E / AndroidRuntime (1164): at dalvik.system.NativeStart.main (Native Method)
Someone mentioned this problem before, but did not solve; Today I again read carefully this code not found under the array bounds ah. . . Brother novice, really do not know how it was.
This is their java daemon program
package com.amaker.wlo;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.amaker.util.HttpUtil;
public class LoginActivity extends Activity {
/ / Declare login, cancel button
private Button cancelBtn, loginBtn;
/ / Declare a user name, password input box
private EditText userEditText, pwdEditText;
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
/ / Set the title
setTitle ("palm-sized wireless ordering system - user login");
/ / Set the current Activity interface layout
setContentView (R.layout.login_system);
/ / Instantiate components
by findViewById methodcancelBtn = (Button) findViewById (R.id.cancelButton);
/ / Instantiate components
by findViewById methodloginBtn = (Button) findViewById (R.id.loginButton);
/ / Instantiate components
by findViewById methoduserEditText = (EditText) findViewById (R.id.userEditText);
/ / Instantiate components
by findViewById methodpwdEditText = (EditText) findViewById (R.id.pwdEditText);
cancelBtn.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
finish ();
}
});
loginBtn.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
if (validate ()) {
if (login ()) {
Intent intent = new Intent (LoginActivity.this, MainMenuActivity.class);
startActivity (intent);
} Else {
showDialog ("User name or password is incorrect, please re-enter!");
}
}
}
});
}
/ / Login method
private boolean login () {
/ / Get the user name
String username = userEditText.getText () toString ();.
/ / Get the password
String pwd = pwdEditText.getText () toString ();.
/ / Get login results
String result = query (username, pwd);
if (result! = null && result.equals ("0")) {
return false;
} Else {
saveUserMsg (result);
return true;
}
}
/ / Save the user information to the configuration file
private void saveUserMsg (String msg) {
/ / User ID
String id = "";
/ / User name
String name = "";
/ / Get information array
String [] msgs = msg.split (";");
. int idx = msgs [0] indexOf ("=");
id = msgs [0] substring (idx +1);.
. idx = msgs [1] indexOf ("=");
. name = msgs [1] substring (idx +1);
/ / Share information
SharedPreferences pre = getSharedPreferences ("user_msg", MODE_WORLD_WRITEABLE);
SharedPreferences.Editor editor = pre.edit ();
editor.putString ("id", id);
editor.putString ("name", name);
editor.commit ();
}
/ / Authentication method
private boolean validate () {
String username = userEditText.getText () toString ();.
if (username.equals ("")) {
showDialog ("User name is required!");
return false;
}
String pwd = pwdEditText.getText () toString ();.
if (pwd.equals ("")) {
showDialog ("User password is required!");
return false;
}
return true;
}
private void showDialog (String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder (this);
builder.setMessage (msg)
. SetCancelable (false)
. SetPositiveButton ("OK", new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create ();
alert.show ();
}
/ / Query the user name password
private String query (String account, String password) {
/ / Query parameters
String queryString = "account =" + account + "& password =" + password;
/ / Url
String url = HttpUtil.BASE_URL + "? Servlet / LoginServlet" + queryString;
/ / Query results
return HttpUtil.queryStringForPost (url);
}
}
Please also
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Are you sure msgs's length> = 2????????
Reply:
me???????? Now to the test, can I use virtual machines directly on your computer to access the server, is not to set ip address 10.0.0.2; localhost access to the database server can be used?
Reply:
11-24 05:34:05.278: D / AndroidRuntime (1437): Shutting down VM
11-24 05:34:05.288: W / dalvikvm (1437): threadid = 1: thread exiting with uncaught exception (group = 0xb1a9fb90)
11-24 05:34:05.338: E / AndroidRuntime (1437): FATAL EXCEPTION: main
11-24 05:34:05.338: E / AndroidRuntime (1437): Process: com.amaker.wlo, PID: 1437
11-24 05:34:05.338: E / AndroidRuntime (1437): java.lang.NullPointerException
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.android.internal.os.LoggingPrintStream.println (LoggingPrintStream.java: 298)
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.amaker.wlo.LoginActivity.saveUserMsg (LoginActivity.java: 79)
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.amaker.wlo.LoginActivity.login (LoginActivity.java: 71)
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.amaker.wlo.LoginActivity.access $ 2 (LoginActivity.java: 61)
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.amaker.wlo.LoginActivity $ 2.onClick (LoginActivity.java: 50)
11-24 05:34:05.338: E / AndroidRuntime (1437): at android.view.View.performClick (View.java: 4424)
11-24 05:34:05.338: E / AndroidRuntime (1437): at android.view.View $ PerformClick.run (View.java: 18383)
11-24 05:34:05.338: E / AndroidRuntime (1437): at android.os.Handler.handleCallback (Handler.java: 733)
11-24 05:34:05.338: E / AndroidRuntime (1437): at android.os.Handler.dispatchMessage (Handler.java: 95)
11-24 05:34:05.338: E / AndroidRuntime (1437): at android.os.Looper.loop (Looper.java: 137)
11-24 05:34:05.338: E / AndroidRuntime (1437): at android.app.ActivityThread.main (ActivityThread.java: 4998)
11-24 05:34:05.338: E / AndroidRuntime (1437): at java.lang.reflect.Method.invokeNative (Native Method)
11-24 05:34:05.338: E / AndroidRuntime (1437): at java.lang.reflect.Method.invoke (Method.java: 515)
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 777)
11-24 05:34:05.338: E / AndroidRuntime (1437): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 593)
11-24 05:34:05.338: E / AndroidRuntime (1437): at dalvik.system.NativeStart.main (Native Method)
Reply:
How has a null pointer
Reply:
What is a request to have the structure of the string, the trouble stickers
Reply:
What is the value of the returned queryStringForPost stickers
No comments:
Post a Comment