1
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        txtUserName=(EditText)this.findViewById(R.id.txtUname);
        txtPassword=(EditText)this.findViewById(R.id.txtPwd);
        btnLogin=(Button)this.findViewById(R.id.btnLogin);
        btnLogin=(Button)this.findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new OnClickListener() {

             Button next = (Button) findViewById(R.id.Button01);
   error1:   next.setOnClickListener(new View.OnClickListener() {   

           public void onClick(View view) {
           Intent myIntent = new Intent(view.getContext(), AddName.class);
           startActivityForResult(myIntent, 0); 
       }}
   error2:  )

       };

    if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
           Toast.makeText(LoginappActivity.this, "Login Successful",Toast.LENGTH_LONG).show();
          } else{
           Toast.makeText(LoginappActivity.this, "Invalid Login",Toast.LENGTH_LONG).show(); 
           }
             }

    }

我创建了一个登录应用程序来从一个意图更改为另一个意图。另一个 .java 工作正常

  • error1:令牌上的语法错误,应改为 AnnotationName

  • error2: 此行有多个标记
    - Syntax error, insert "EnumBody" to complete EnumDeclaration
    - Syntax error, insert "enum Identifier" to complete EnumHeaderName
    - Syntax error, insert ")" to complete Expression
    -Syntax error, insert "}" to complete ClassBody

4

2 回答 2

3

在函数}}的末尾你有一些额外的东西。onClick它应该是:

next.setOnClickListener(new View.OnClickListener() {   

       public void onClick(View view) {
           Intent myIntent = new Intent(view.getContext(), AddName.class);
           startActivityForResult(myIntent, 0); 
       }
});

顺便说一句,我发现 onClickListener 在另一个 onClickListener 中的用法非常令人困惑。你应该把它们分开。

于 2012-05-08T07:52:22.373 回答
1

它必须像:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

     txtUserName = (EditText) this.findViewById(R.id.txtUname);
     txtPassword = (EditText) this.findViewById(R.id.txtPwd);
    Button btnLogin = (Button) this.findViewById(R.id.btnLogin);

    btnLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if ((txtUserName.getText().toString()).equals(txtPassword.getText()
            .toString())) {
        Toast.makeText(DelActivity.this, "Login Successful",
                Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(DelActivity.this, "Invalid Login",
                Toast.LENGTH_LONG).show();
    }
        }
    });

    Button next = (Button) findViewById(R.id.button1);
    next.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            //Intent myIntent = new Intent(view.getContext(), AddName.class);
            //startActivityForResult(myIntent, 0);
        }
    });

}
于 2012-05-08T07:57:00.047 回答