我正在尝试密码保护我的应用程序,以便主要活动允许用户输入密码,然后通过按下按钮提交。
我已经复制了另一个问题Password protecting my android app (the simple way)
中的代码import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class PasswordMenu extends Activity {
MediaPlayer mpbuttonclick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.activity_password_menu);
mpbuttonclick = MediaPlayer.create(this, R.raw.keypress);
Button sumbitButton = (Button) findViewById(R.id.button_enterpassword);
sumbitButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText passwordEditText = (EditText) findViewById(R.id.text_enterpassword);
if (passwordEditText.getText().toString().equals("Test")) {
startActivity(new Intent("com.berry.intro"));
mpbuttonclick.start();
}
}
});
}
public void openMenu(View view) {
Intent intent = new Intent(this , MainMenu.class);
startActivity(intent);
}
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.password_menu, menu);
return true;
}*/
}
然而,在进行了一些小改动以使其适合我的应用程序之后,我在行
处收到了错误消息mpbuttonclick = MediaPlayer.create(this, R.raw.keypress);
其中raw“无法解析或不是字段”。有人能告诉我为什么会收到这个错误吗?