ID给出空指针异常

时间:2014-01-27 09:04:36

标签: android nullpointerexception number-formatting

您好我正在尝试创建联系人列表应用程序,在我的contactEdit类中我使用了子活动概念,但它在rowId=Long.parseLong(id.trim());给了我空指针异常我很累但是无法得到任何解决方案请帮助我我觉得我觉得有一些解析问题,

 public class ContactEdit extends Activity {

    protected EditText nameText;
    private EditText addressText;
    private EditText mobileText;
    private EditText homeText;
    public long rowId;
      Button submitButton;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("database1" ,"button4");
        setContentView(R.layout.contact_edit);
        Log.d("database1" ,"button5");
        nameText = (EditText) findViewById(R.id.textName);
        addressText = (EditText) findViewById(R.id.textAddress);
        mobileText  = (EditText) findViewById(R.id.textMobile);
        homeText    = (EditText) findViewById(R.id.textHome);
        Button submitButton = (Button) findViewById(R.id.BtnSave);
        //long rowId = (Long) null;
        Intent extras = getIntent();
        Log.d("database1" ,"button5");

        if (extras != null){
            //get all the values for the corresponding keys
            String name = extras.getStringExtra(DBHandler.Key_Name);
            String address = extras.getStringExtra(DBHandler.Key_Address);
            String mobile = extras.getStringExtra(DBHandler.Key_Phone);
            String home = extras.getStringExtra(DBHandler.Key_Home);
            String id = extras.getStringExtra(DBHandler.Key_ID);
            Log.d("database1" ,"button6");

             rowId=Long.parseLong(id.trim()); // giving null pointer exception
             if (rowId != (Long)null)
             {
                 Log.d("foract","gact");
             }
             else {
                 Log.d("foract","gactttt");
             }

            if (name !=null){
                nameText.setText(name);
            }
            if (address != null){
                addressText.setText(address);
            }
            if (mobile != null){
                mobileText.setText(mobile);
            }
            if (home != null){
                homeText.setText(home);
            }

        }


      submitButton.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v){
        //Intent bundle = new Bundle();
        Intent intent=new Intent();

        intent.putExtra(DBHandler.Key_Name, nameText.getText().toString());
        intent.putExtra(DBHandler.Key_Address, addressText.getText().toString());
        intent.putExtra(DBHandler.Key_Phone, mobileText.getText().toString());
        intent.putExtra(DBHandler.Key_Home, homeText.getText().toString());
        if ((rowId!=(Long) null)) {
            intent.putExtra(DBHandler.Key_ID, rowId);
        }
        setResult(RESULT_OK,intent);
        Log.e("what","result set");
        finish();
    }

    public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub

    }
});
}}

0 个答案:

没有答案