| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 490 人关注过本帖
标题:帮帮忙解决一下里面的问题,读取数据那块可能出错了
只看楼主 加入收藏
王洋爱135
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-8-15
结帖率:0
收藏
 问题点数:0 回复次数:1 
帮帮忙解决一下里面的问题,读取数据那块可能出错了
注册代码:package

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;

public class AssistantRegister extends Activity
{
    static EditText userName01;
    static EditText password01;
    Sql db;
    SQLiteDatabase sDatabase = null;
    public void close()
    {
        /*if(mCursor!=null){
            mCursor.close();
        }*/
        sDatabase.close();
    }
    private ImageButton dpress;
    private ImageButton dpress2;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        
            super.onCreate(savedInstanceState);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.register);
            
            userName01 = (EditText)findViewById(R.id.text3);
            password01 = (EditText)findViewById(R.id.text4);
            this.dpress=(ImageButton)findViewById(R.id.Click_Button12);
            this.dpress2=(ImageButton)findViewById(R.id.Click_Button13);
      
            dpress.setOnClickListener(new android.view.View.OnClickListener()
            {
            public void onClick(View v)
            {
                db = new Sql(getApplicationContext(), "store.db", null, 1);
                sDatabase = db.getWritableDatabase();
                if (userName01.getText().toString().equals("")
                                || password01.getText().toString().equals(""))
                {

                            DialogDemo.builder(AssistantRegister.this, "错误信息", "请填写完整信息!");

                        
                }
                else
                {
                    int id1=0;
                    String select = "select max(_id) from user_info";
                    Cursor seCursor = sDatabase.rawQuery(select, null);
                    seCursor.moveToFirst();
                    id1 = Integer.parseInt(seCursor.getString(0));
                    id1 += 1;
                    sDatabase.execSQL("insert into user_info values('" + id1 + "','"
                                            + userName01 + "','" + password01 + "')"
                                            );
                    DialogDemo.builder(AssistantRegister.this, "提示", "注册成功,请返回登录界面登录");
                                    //seCursor.close();
                                    sDatabase.close();
                 
                    
                }
                        
                        
            }
        } );
        dpress2.setOnClickListener(new android.view.View.OnClickListener()
        {
            public void onClick(View v)
            {
                /* 新建一个Intent对象 */
                Intent intent = new Intent();
                /* 指定intent要启动的类 */
                intent.setClass(AssistantRegister.this,AssistantLoadActivity.class);
                /* 启动一个新的Activity */
                startActivity(intent);
                /* 关闭当前的Activity */
                AssistantRegister.this.finish();
               
            }
            
        } );
   
    }
   
}

登陆代码:
package

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class AssistantLoad extends Activity
{
    private ImageButton dpress;
    private ImageButton dpress2;
    private EditText use,password;
    Sql db;
    SQLiteDatabase sDatabase = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.denglu);
        use = (EditText)findViewById(R.id.text1);
        password = (EditText)findViewById(R.id.text2);
       this.dpress=(ImageButton)findViewById(R.id.Click_Button8);
       this.dpress2=(ImageButton)findViewById(R.id.Click_Button9);
       db = new Sql(getApplicationContext(), "store.db", null, 1);
        sDatabase = db.getWritableDatabase();
        dpress.setOnClickListener(new android.view.View.OnClickListener()
        {
            public void onClick(View v)
            {
                String i = use.getText().toString();
                //String i1 = password.getText().toString();
                String userName = "";
                String userPw = "";
                //编写数据库语句
                String select_sql = "select username,password from user_info where username = '"
                        + i + "'";
                //执行语句
                Cursor cursor = sDatabase.rawQuery(select_sql, null);
                if(cursor!=null){
                cursor.moveToFirst();
               
                try
                {
                    
                    userName = cursor.getString(1);
                    userPw = cursor.getString(2);
                    
                }
                catch (Exception e)
                {
                    // TODO: handle exception
                    userName = "";
                    userPw = "";
                }}
//                判断用户名是否为空
                if (i.equals(""))
                {
                    DialogDemo.builder(AssistantLoad.this, "错误信息",
                            "用户名不能为空!");
                }
//                判断密码是否为空
                else if (password.getText().toString().equals(""))
                {
                    DialogDemo.builder(AssistantLoad.this, "错误信息",
                            "密码不能为空!");
                }
               
//                判断用户名和密码是否正确
                else if (!(use.getText().toString().equals(userName) && password
                        .getText().toString().equals(userPw)))
                {
                    DialogDemo.builder(AssistantLoad.this, "错误信息",
                            "用户名或密码错误,请重新输入");
                }
//                全部正确跳转到操作界面
                else
                {
                    cursor.close();
                    Intent intent = new Intent();
                    //Bundle bundle = new Bundle();
                    //bundle.putString("username",userName);
                    //intent.putExtras(bundle);
                    intent.setClass(AssistantLoad.this, Assistant.class);
                    startActivity(intent);
                    
                    Toast.makeText(AssistantLoad.this, "登陆成功", Toast.LENGTH_SHORT).show();
                    

                }
               
            }
            
        } );
        dpress2.setOnClickListener(new android.view.View.OnClickListener()
        {
            public void onClick(View v)
            {
                /* 新建一个Intent对象 */
                Intent intent = new Intent();
                /* 指定intent要启动的类 */
                intent.setClass(AssistantLoad.this,AssistantLoadActivity.class);
                /* 启动一个新的Activity */
                startActivity(intent);
                /* 关闭当前的Activity */
                AssistantLoad.this.finish();
            }
            
        } );
   
    }
   
}
搜索更多相关主题的帖子: import void public null package 
2012-08-15 11:30
王洋爱135
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-8-15
收藏
得分:0 
有谁帮忙看看看看啊
2012-08-16 16:07
快速回复:帮帮忙解决一下里面的问题,读取数据那块可能出错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014265 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved