关于Android项目出现unfortunately 登陆对话框has stopped
publicclassMainextendsActivityimplementsOnClickListener{privatefinalViewview;publicMa...
public class Main extends Activity implements OnClickListener
{
private final View view;
public Main(View view){
this.view=view;
}
@Override
public void onClick(View v)
{
LinearLayout loginLayout = (LinearLayout) getLayoutInflater().inflate(
R.layout.login, null);
new AlertDialog.Builder(this).setIcon(R.drawable.login)
.setTitle("用户登录").setView(loginLayout).setPositiveButton("登录",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton)
{
if(whichButton==DialogInterface.BUTTON_POSITIVE){
EditText textUserName=(EditText)(view.findViewById(R.id.textUserName));
EditText textPassword=(EditText)(view.findViewById(R.id.textPassword));
String userName=textUserName.getText().toString();
String password=textPassword.getText().toString();
if(userName.equals("Admin")&&password.equals("psw")){
Toast toast=Toast.makeText(getApplicationContext(),"登陆成功",Toast.LENGTH_SHORT);
toast.show();
}
else{
Toast toast=Toast.makeText(getApplicationContext(),"登陆失败",Toast.LENGTH_SHORT);
toast.show();
}
}
else{
Toast toast=Toast.makeText(getApplicationContext(),"取消了登陆操作",Toast.LENGTH_SHORT);
toast.show();
}
}
}).show();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
}
}
这是我写的一段代码,不知道哪里有问题,一运行就提示has stopped,求大家帮忙解决。 展开
{
private final View view;
public Main(View view){
this.view=view;
}
@Override
public void onClick(View v)
{
LinearLayout loginLayout = (LinearLayout) getLayoutInflater().inflate(
R.layout.login, null);
new AlertDialog.Builder(this).setIcon(R.drawable.login)
.setTitle("用户登录").setView(loginLayout).setPositiveButton("登录",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton)
{
if(whichButton==DialogInterface.BUTTON_POSITIVE){
EditText textUserName=(EditText)(view.findViewById(R.id.textUserName));
EditText textPassword=(EditText)(view.findViewById(R.id.textPassword));
String userName=textUserName.getText().toString();
String password=textPassword.getText().toString();
if(userName.equals("Admin")&&password.equals("psw")){
Toast toast=Toast.makeText(getApplicationContext(),"登陆成功",Toast.LENGTH_SHORT);
toast.show();
}
else{
Toast toast=Toast.makeText(getApplicationContext(),"登陆失败",Toast.LENGTH_SHORT);
toast.show();
}
}
else{
Toast toast=Toast.makeText(getApplicationContext(),"取消了登陆操作",Toast.LENGTH_SHORT);
toast.show();
}
}
}).show();
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
}
}
这是我写的一段代码,不知道哪里有问题,一运行就提示has stopped,求大家帮忙解决。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询