0

問題がどこにあるのか理解できず、アプリケーションを実行できません

nさらに行彼らは私のコードです

コード:pass1:-

public class Pass1 extends Activity {

    EditText pno=(EditText)findViewById(R.id.editText1);
Button btn=(Button)findViewById(R.id.button1);
String pn=pno.getText().toString();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pass1);

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(pn.charAt(0)=='9' || pn.charAt(0)=='8' || pn.charAt(0)=='7')
            {
                if (pno.getText().toString().length()==10)
                {
                 Intent i= new Intent(Pass1.this, Pass2.class);
                        i.putExtra("phoneno", pn);
                                startActivity(i);                   
                }
        }
        else
            pno.setError("The entered number is invalid!!");


            }               
        });
    }
}

pass2:-

public class Pass2 extends Activity {

EditText codetxt=(EditText)findViewById(R.id.editText1);

String ph=codetxt.getText().toString();

Button codebtn=(Button)findViewById(R.id.button1);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent i = getIntent();
        final String phn = i.getStringExtra("phoneno");


setContentView(R.layout.activity_pass2);
            codebtn.setOnClickListener(new View.OnClickListener() {

                @Override


public void onClick(View v) {
                // TODO Auto-generated method stub
                if(ph.charAt(0)==phn.charAt(0) && ph.charAt(1)==phn.charAt(5) && ph.charAt(2)==phn.charAt(4) && ph.charAt(3)==phn.charAt(9))
                {
                    if( codetxt.getText().toString().length()==4)
                    {
                        //code.setError("right number");
                        Intent i=new Intent(Pass2.this,Pass3.class);
                        startActivity(i);
                    }
                }
                else
                    codetxt.setError("Entered Code is wrong!"); 
            }
        });
    }
}
4

3 に答える 3

2

このコードを移動

 EditText pno=(EditText)findViewById(R.id.editText1);
Button btn=(Button)findViewById(R.id.button1);
String pn=pno.getText().toString();  

setContentView() 行の後の onCreate() 内。同様に Pass2 についても

于 2013-03-08T18:14:28.023 に答える
0

findViewById()後に使用する必要がありますsetContentView()

于 2013-03-08T18:17:09.083 に答える
0

現在のアクティビティで、新しいインテントを作成します。

Intent i = new Intent(getApplicationContext(), NewActivity.class);
i.putExtra("new_variable_name","value");
startActivity(i);

次に、新しいアクティビティで、これらの値を取得します。

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("new_variable_name");
}

あなたの場合

Bundle extras = getIntent().getExtras();
        final String phn = extras.getString("phoneno");
于 2013-03-08T18:11:07.817 に答える