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)
之前有人提过这个问题,但是没解决好;我今天又把这个代码仔细读了下没发现数组越界啊。。。小弟新手,实在不知怎么回事。
这是其后台程序java程序
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 {
// 声明登录、取消按钮
private Button cancelBtn,loginBtn;
// 声明用户名、密码输入框
private EditText userEditText,pwdEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置标题
setTitle("掌中宝无线订餐系统-用户登录");
// 设置当前Activity界面布局
setContentView(R.layout.login_system);
// 通过findViewById方法实例化组件
cancelBtn = (Button)findViewById(R.id.cancelButton);
// 通过findViewById方法实例化组件
loginBtn = (Button)findViewById(R.id.loginButton);
// 通过findViewById方法实例化组件
userEditText = (EditText)findViewById(R.id.userEditText);
// 通过findViewById方法实例化组件
pwdEditText = (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("用户名称或者密码错误,请重新输入!");
}
}
}
});
}
// 登录方法
private boolean login(){
// 获得用户名称
String username = userEditText.getText().toString();
// 获得密码
String pwd = pwdEditText.getText().toString();
// 获得登录结果
String result=query(username,pwd);
if(result!=null&&result.equals("0")){
return false;
}else{
saveUserMsg(result);
return true;
}
}
// 将用户信息保存到配置文件
private void saveUserMsg(String msg){
// 用户编号
String id = "";
// 用户名称
String name = "";
// 获得信息数组
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);
// 共享信息
SharedPreferences pre = getSharedPreferences("user_msg", MODE_WORLD_WRITEABLE);
SharedPreferences.Editor editor = pre.edit();
editor.putString("id", id);
editor.putString("name", name);
editor.commit();
}
// 验证方法
private boolean validate(){
String username = userEditText.getText().toString();
if(username.equals("")){
showDialog("用户名称是必填项!");
return false;
}
String pwd = pwdEditText.getText().toString();
if(pwd.equals("")){