EditText et1=(EditText)findViewById(R.id.editText1);//gives nulllpointerexception here.. as well at all the linking code below
EditText et2=(EditText)findViewById(R.id.editText2);
EditText et3=(EditText)findViewById(R.id.editText3);
EditText et4=(EditText)findViewById(R.id.editText4);
Button bt1=(Button)findViewById(R.id.button1);
Button bt2=(Button)findViewById(R.id.button2);
Button bt3=(Button)findViewById(R.id.button3);
Button bt4=(Button)findViewById(R.id.button4);
Button bt5=(Button)findViewById(R.id.button5);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onContacts(View v)
{
Intent i=new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI);
startActivity(i);
}
public void onBrowse(View v)
{
String s1= et1.getText().toString();
Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse(s1));
startActivity(i);
}
public void onSearch(View v)
{
String s1= et2.getText().toString();
Intent i=new Intent(Intent.ACTION_WEB_SEARCH);
i.putExtra(SearchManager.QUERY, s1);
startActivity(i);
}
public void onMap(View v)
{
String s1= et3.getText().toString();
Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse("geo:0,0?q="+s1));
startActivity(i);
}
public void onCall(View v)
{
String s1= et4.getText().toString();
Intent i=new Intent(Intent.ACTION_SEARCH,Uri.parse("tel:"+s1));
startActivity(i);
}
這裏我首先寫了方法代碼,然後將edittext元素鏈接到佈局就是導致這個錯誤? 但我不這麼認爲,因爲我已經這樣做過...Android:NullpointerException
當我把editext鏈接代碼行的各自的方法,他們已經使用它不顯示任何錯誤,爲什麼這樣呢?我的意思是,這是不是第一次 我聲明全局的EditText項目...
thnx的解釋 – ceanan007