public class MainActivity extends Activity {
EditText oETextN;
EditText oETextPh;
Button oButtonSave;
public String givenName;
public String givenPhNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
findViewsById();
oButtonSave.setOnClickListener(new OnClickListener(){
public void onClick(View view){
givenName = oETextN.getText().toString();
givenPhNum = oETextPh.getText().toString();
OrgiOperations.Insert2Contacts(getApplicationContext(),
givenName, givenPhNum);
if (OrgiOperations.isTheNumberExistsinContacts(
getApplicationContext(), givenPhNum)) {
Log.i(OrgiOperations.TAG, "Exists");
} else {
Log.i(OrgiOperations.TAG, "Not Exists");
}
}
});
setContentView(R.layout.activity_main);
}
private void findViewsById(){
oButtonSave = (Button) findViewById(R.id.SaveBtn);
oETextN = (EditText) findViewById(R.id.FLName);
oETextPh = (EditText) findViewById(R.id.Ph);
//oEText = (EditText) findViewById(R.id.Name);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我一直在試圖製作一個簡單的Android應用程序,將輸入的詳細信息(姓名和電話號碼)直接保存到您的設備電話簿中。這是MAIN活動,另一個類包含執行此操作的功能,我相信這是正確實施的。如何調試Android應用程序強制關閉錯誤?
當我在手機上運行應用程序時出現問題,而且經過幾個小時的冷碼後,我得到了FORCE CLOSE錯誤!
小時?你的日誌發生了什麼? –
'findViewsById'應該在'setContentView'後面調用 –