2016-03-07 83 views
0

我試着去創建一個簡單的登錄我的移動應用程序,但即時通訊getiing股票有一個錯誤:太虛不能轉換成字符串

Login.java 
public void onButtonClick(View v) { 
    if (v.getId() == R.id.BLogin) { 
     EditText a = (EditText) findViewById(R.id.TFusername); 
     String str = a.getText().toString(); 
     EditText b = (EditText) findViewById(R.id.TFpassword); 
     String pass = b.getText().toString(); 

     String password = helper.searchPass(str); 
     if (pass.equals(password)) { 
      Intent i = new Intent(LogIn.this, Display.class); 
      i.putExtra("Username", str); 
      startActivity(i); 
     } else { 
      Toast temp = Toast.makeText(LogIn.this, "Username and password don't match!", Toast.LENGTH_SHORT); 
      temp.show(); 
     } 

    } 
    if (v.getId() == R.id.BSignup) { 
     Intent i = new Intent(LogIn.this, Signup.class); 
     startActivity(i); 
    } 
} 

和數據庫處理器

public void searchPass(String uname) 
{ 
    db = this.getReadableDatabase(); 
    String query = " select uname, pass from "+TABLE_NAME; 
    Cursor cursor = db.rawQuery(query , null); 
    String a, b; 
    b = "not found"; 
    if(cursor.moveToFirst()) 
    { 
     do { 
      a = cursor.getString(0); 


      if(a.equals(uname)) 
      { 
       b = cursor.getString(1); 
       break; 
      } 
     } 
     while (cursor.moveToNext()); 
    } 
    return b; 
} 

即時得到堅持的錯誤: 錯誤:(32,48)錯誤:不兼容的類型:void無法轉換爲字符串 String password = helper.searchPass(s​​tr); 有人知道我在想什麼嗎?

+0

你的方法searchPass searchPass返回void。你不能將它分配給一個字符串。我認爲你的意思是公共字符串searchPass –

回答

3

更換返回類型爲字符串中

public String searchPass(String uname) 
{ 
db = this.getReadableDatabase(); 
String query = " select uname, pass from "+TABLE_NAME; 
Cursor cursor = db.rawQuery(query , null); 
String a, b; 
b = "not found"; 
if(cursor.moveToFirst()) 
{ 
    do { 
     a = cursor.getString(0); 


     if(a.equals(uname)) 
     { 
      b = cursor.getString(1); 
      break; 
     } 
    } 
    while (cursor.moveToNext()); 
} 
return b; 
}