0
public class RegisterActivity  extends Activity{
   TextView tv1,tv2;
   Button b;
    EditText email,nname,npassword,phone,repassword,usernam;
   ImageView iv;
     Button btnCreateAccount;
    private DatabaseRegister dbHelper;
@Override
  protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
     setContentView(R.layout.register);
//  dbHelper = new DatabaseRegister(this);
    dbHelper.open();

  initControls();
    }
       private void initControls()
      {
tv1=(TextView)findViewById(R.id.tv_register_job);
tv2=(TextView)findViewById(R.id.tv_fill_data);
    b=(Button)findViewById(R.id.btn_register);
       email=(EditText)findViewById(R.id.et_email);
      nname=(EditText)findViewById(R.id.et_name);
      npassword=(EditText)findViewById(R.id.et_password);
     phone=(EditText)findViewById(R.id.et_phone);
       repassword=(EditText)findViewById(R.id.et_repass);
       usernam=(EditText)findViewById(R.id.et_username);
      iv=(ImageView)findViewById(R.id.iv_search);
   btnCreateAccount.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    Log.i("click", "button");
   }
        });

          }
          private void ClearForm()
         {

        usernam.setText("");
           nname.setText("");
          npassword.setText("");
         email.setText("");
       repassword.setText("");
             phone.setText("");
          }
        private void RegisterMe(View v)
         {
//Get user details. 
String username = usernam.getText().toString();
String password = npassword.getText().toString();
String confirmpassword = repassword.getText().toString();
String name=nname.getText().toString();
String contact=phone.getText().toString();
String emailid=email.getText().toString();
//Check if all fields have been completed.
if (username.equals("") || password.equals("")||confirmpassword.equals("")||name.equals("")||contact.equals("")||email id.equals("")){
    Toast.makeText(getApplicationContext(), 
            "Please ensure all fields have been completed.",
              Toast.LENGTH_SHORT).show();
    return;
    }

//Check password match. 
   if (!password.equals(confirmpassword)) {
    Toast.makeText(getApplicationContext(), 
            "The password does not match.",
                Toast.LENGTH_SHORT).show();
                npassword.setText("");
                repassword.setText("");
    return;
   }

//Encrypt password with MD5.
password = md5(password);

//Check database for existing users.
Cursor user = dbHelper.fetchUser(username, password, confirmpassword, emailid, name, contact);
if (user == null) {
    Toast.makeText(getApplicationContext(), "Database query error",
              Toast.LENGTH_SHORT).show();
} else {
    startManagingCursor(user);

    //Check for duplicate usernames
    if (user.getCount() > 0) {
        Toast.makeText(getApplicationContext(), "The username is already registered",
                  Toast.LENGTH_SHORT).show();
        stopManagingCursor(user);
        user.close();
        return;
    }
    stopManagingCursor(user);
    user.close();
    user = dbHelper.fetchUser(username, password, emailid, name, contact, confirmpassword);
    if (user == null) {
        Toast.makeText(getApplicationContext(), "Database query error",
                  Toast.LENGTH_SHORT).show();
        return;
    } else {
        startManagingCursor(user);

        if (user.getCount() > 0) {
            Toast.makeText(getApplicationContext(), "The username is already registered",
                      Toast.LENGTH_SHORT).show();
            stopManagingCursor(user);
            user.close();
            return;
        }
        stopManagingCursor(user);
        user.close();
    }
    //Create the new username.
    long id = dbHelper.createUser(username, password, emailid, name, contact, confirmpassword);
    if (id > 0) {
        Toast.makeText(getApplicationContext(), "Your username was created",
                  Toast.LENGTH_SHORT).show();
        saveLoggedInUId(id, username, password,confirmpassword, emailid, name,contact);
        Intent i = new Intent(v.getContext(), MainActivity.class);
        startActivity(i);

        finish();
    } else {
        Toast.makeText(getApplicationContext(), "Failt to create new username",
                  Toast.LENGTH_SHORT).show();
            }
          }
     }

private void saveLoggedInUId(long id, String username, String password,String name,String contact,String email,String repass) {
SharedPreferences settings = getSharedPreferences(login.MY_PREFS, 0);
Editor editor = settings.edit();
editor.putLong("uid", id);
editor.putString("username", username);
editor.putString("password", password);
editor.putString("repass", repass);
editor.putString("name", name);
editor.putString("emailid", email);
editor.putString("contact", contact);

editor.commit();
          }
         /**
         * Hashes the password with MD5.  
           *        @param s
        * @return
     */
      private String md5(String s) {
          try {

MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();


StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
    hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();

      } catch (NoSuchAlgorithmException e) {
return s;
   }
     }
      }

我正在制作一个登录和注册表单,其中我的数据将存储在 SQLite 数据库中。当我点击注册按钮时,它给了我这个错误:

NoClassFound 差异

我该如何解决这个问题?

这是我的日志:

 11-06 06:03:32.951: I/dalvikvm(803): Could not find method      com.example.jobportal.RegisterActivity.RegisterMe
11-06 06:03:32.991: W/dalvikvm(803): VFY: unable to resolve virtual method 4635:   Lcom/android/database/DatabaseRegister;.fetchUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;
11-06 06:03:32.991: D/dalvikvm(803): VFY: replacing opcode 0x74 at 0x00b8
11-06 06:03:33.036: I/dalvikvm(803): Could not find method com.android.database.DatabaseRegister.open, referenced from method com.example.jobportal.RegisterActivity.onCreate
11-06 06:03:33.036: W/dalvikvm(803): VFY: unable to resolve virtual method 4636: Lcom/android/database/DatabaseRegister;.open ()Lcom/android/database/DatabaseRegister;
11-06 06:03:33.041: D/dalvikvm(803): VFY: replacing opcode 0x6e at 0x000b
11-06 06:03:33.570: D/AndroidRuntime(803): Shutting down VM
11-06 06:03:33.570: W/dalvikvm(803): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
11-06 06:03:33.630: E/AndroidRuntime(803): FATAL EXCEPTION: main
11-06 06:03:33.630: E/AndroidRuntime(803): java.lang.NoClassDefFoundError: com.android.database.DatabaseRegister
11-06 06:03:33.630: E/AndroidRuntime(803):  at com.example.jobportal.RegisterActivity.onCreate(RegisterActivity.java:38)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.Activity.performCreate(Activity.java:5104)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.os.Looper.loop(Looper.java:137)
11-06 06:03:33.630: E/AndroidRuntime(803):  at android.app.ActivityThread.main(ActivityThread.java:5041)
11-06 06:03:33.630: E/AndroidRuntime(803):  at java.lang.reflect.Method.invokeNative(Native Method)
11-06 06:03:33.630: E/AndroidRuntime(803):  at java.lang.reflect.Method.invoke(Method.java:511)
11-06 06:03:33.630: E/AndroidRuntime(803):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-06 06:03:33.630: E/AndroidRuntime(803):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-06 06:03:33.630: E/AndroidRuntime(803):  at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

1

看起来您还没有初始化 dbHelper 对象。只需将代码替换如下:

     super.onCreate(savedInstanceState);
     setContentView(R.layout.register);
     dbHelper = new DatabaseRegister(this);// you need to initialize it before access.
     dbHelper.open();
于 2013-11-06T06:06:25.363 回答
0

因为NoClassDefFoundError我有同样的问题,我做了以下来解决这个问题。

  1. 转到项目的“属性”。
  2. 选择“Java 构建路径”
  3. 选择“订购和导出”选项卡
  4. 您应该在此处看到所选项目的“src”和“gen”路径和依赖项。
  5. 他们列出的顺序首先是“src”,然后是“gen”路径
  6. 我切换它们,以便在“src”之前构建“gen”文件夹

gen- 项目中的自动化代码(来自依赖项和引用) src- 项目中的源代码

无需重新启动 Eclipse。它刚刚开始工作。

于 2013-11-06T06:12:34.497 回答
-1

你应该初始化 btnCreateAccount

于 2013-11-06T06:17:45.737 回答