【发布时间】:2014-02-16 05:26:17
【问题描述】:
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 活动,其他类包含执行此操作的函数,我确信这些函数已正确实现。
当我在手机上运行应用程序时,问题就出现了,不幸的是,经过数小时的冷编码后,我得到了 FORCE CLOSE 错误!
【问题讨论】:
-
小时?你的日志怎么了?
-
findViewsById应该在setContentView之后调用
标签: java android xml forceclose