嗨,我是Android编码的新手,现在我正在学习SQLite来登录系统...而且我遇到了模拟器甚至无法运行这个项目的问题。它会从此代码中显示Toast“welcome_error_message”
Toast.makeText(this,getString(R.string.welcome_error_message),Toast.LENGTH_SHORT).show()
仅供参考我运行ADB模拟器 现在,我不知道究竟是什么问题,我尝试更新SDK管理器中的所有内容,并从现有问题帖子中找到解决方案,但找不到与我的项目相同的内容。
是否有可能为我提出解决方案?
请在下面找到我的来源
[MainActivity.java]
public class MainActivity extends AppCompatActivity {
Button mChangePassword; TextView mUsername; private UserManager mManager; User mUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mManager = new UserManager(this);
mUser = new User();
mChangePassword = (Button) findViewById(R.id.change_password);
mUsername = (TextView) findViewById(R.id.say_hi);
Bundle args = getIntent().getExtras();
if (null == args) {
Toast.makeText(this, getString(R.string.welcome_error_message),
Toast.LENGTH_SHORT).show();
finish();
} else {
mUsername.setText(getString(R.string.say_hi) + " " +
args.getString(User.Column.USERNAME));
mUser.setId(args.getInt(User.Column.ID));
mUser.setUsername(args.getString(User.Column.USERNAME));
}
mChangePassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialogPassword();
}
});
}
}
[User.java]
public class User {
public static final String TABLE = "user";
public class Column {
public static final String ID = BaseColumns._ID;
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
}
private int id; private String username; private String password;
public User(String username, String password) {
this.username = username;
this.password = password;
}
public User() {}
public int getId() {return id;}
public void setId(int id) {this.id = id;}
public String getUsername() {return username;}
public void setUsername(String username) {this.username = username;}
public String getPassword() {return password;}
public void setPassword(String password) {this.password = password;}
}
[UserManager.java]
public class UserManager extends SQLiteOpenHelper implements UserManagerHelper {
public static final String TAG = UserManager.class.getSimpleName();
private SQLiteDatabase mDatabase;
public UserManager(Context context) {
super(context, UserManagerHelper.DATABASE_NAME, null, UserManagerHelper.DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE_USER = String.format("CREATE TABLE %s " +
"(%s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT, %s TEXT)" ,
User.TABLE,
User.Column.ID,
User.Column.USERNAME,
User.Column.PASSWORD
);
db.execSQL(CREATE_TABLE_USER);
Log.i(TAG, CREATE_TABLE_USER);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String DROP_USER = "DROP TABLE IF EXISTS " + UserManagerHelper.DATABASE_VERSION;
db.execSQL(DROP_USER);
Log.i(TAG, DROP_USER);
onCreate(mDatabase);
}
@Override
public long registerUser(User user) {
mDatabase = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(User.Column.USERNAME, user.getUsername());
values.put(User.Column.PASSWORD, user.getPassword());
long result = mDatabase.insert(User.TABLE, null, values);
mDatabase.close();
return result;
}
@Override
public User checkUserLogin(User user) {
mDatabase = this.getReadableDatabase();
Cursor cursor = mDatabase.query(User.TABLE,null,User.Column.USERNAME + " = ? AND " +
User.Column.PASSWORD + " = ?",new String[]{user.getUsername(), user.getPassword()},null,null,null);
User currentUser = new User();
if (cursor != null) {
if (cursor.moveToFirst()) {
currentUser.setId((int) cursor.getLong(0));
currentUser.setUsername(cursor.getString(1));
currentUser.setPassword(cursor.getString(2));
mDatabase.close();
return currentUser;
}
}
return null;
}
}
[UserManagerHelper.interface]
public interface UserManagerHelper {
public static final String DATABASE_NAME = "ahoy_login";
public static final int DATABASE_VERSION = 1;
public long registerUser(User user);
public User checkUserLogin(User user);
}
[logcat的]
02-25 13:54:22.657 3297-3297/? E/libprocessgroup: failed to make and chown /acct/uid_10060: Read-only file system
02-25 13:54:22.657 3297-3297/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
02-25 13:54:22.658 3297-3297/? I/art: Not late-enabling -Xcheck:jni (already on)
02-25 13:54:22.702 3297-3297/com.gerpeace.databasetest I/InstantRun: Instant Run Runtime started. Android package is com.gerpeace.databasetest, real application class is null.
02-25 13:54:22.704 3297-3297/com.gerpeace.databasetest W/art: Failed to find OatDexFile for DexFile /data/data/com.gerpeace.databasetest/files/instant-run/dex/slice-slice_4-classes.dex ( canonical path /data/data/com.gerpeace.databasetest/files/instant-run/dex/slice-slice_4-classes.dex) with checksum 0x3b5a494f in OatFile /data/data/com.gerpeace.databasetest/cache/slice-slice_4-classes.dex
02-25 13:54:22.903 3297-3297/com.gerpeace.databasetest W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-25 13:54:23.033 3297-3317/com.gerpeace.databasetest D/OpenGLRenderer: Render dirty regions requested: true
[ 02-25 13:54:23.034 3297: 3297 D/ ]
HostConnection::get() New Host Connection established 0xac67c160, tid 3297
02-25 13:54:23.037 3297-3297/com.gerpeace.databasetest D/Atlas: Validating map...
[ 02-25 13:54:23.075 3297: 3317 D/ ]
HostConnection::get() New Host Connection established 0xaf20e1f0, tid 3317
02-25 13:54:23.077 3297-3317/com.gerpeace.databasetest I/OpenGLRenderer: Initialized EGL, version 1.4
02-25 13:54:23.102 3297-3317/com.gerpeace.databasetest D/OpenGLRenderer: Enabling debug mode 0
02-25 13:54:23.180 3297-3317/com.gerpeace.databasetest V/RenderScript: 0xa3f02c00 Launching thread(s), CPUs 2