更新:已修复,这是由于视图中缺少属性以及我不知道如何使用调试器:)
-
调试应用程序
-
-
-
我在第一行碰到了一个断点
GoalEdit.onCreate
得到这些警告:
b(ActivityManager)HistoryRecord{…}的活动空闲超时
-
我有一个断点在
setContentView
GoalEdit.onCreate创建
-通过后:
答。ActivityThread.perfo:找不到源。
相关代码如下:
目标列表.java
/**
* Add a menu to this activity
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID, 0, R.string.menu_insert);
return true;
}
/**
* Catch the menuItemSelected event
*/
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case INSERT_ID:
createGoal();
return true;
}
return super.onMenuItemSelected(featureId, item);
}
/**
* Open the Edit activity to create a new goal
*/
private void createGoal() {
Intent i = new Intent(this, GoalEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
GoalEdit.java文件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbGoals = new GoalDbTable(this);
mDbGoals.open();
setContentView(R.layout.goal_edit);
mName = (EditText) findViewById(R.id.name);
Button finishBtn = (Button) findViewById(R.id.finish);
mRowId = (savedInstanceState == null) ? null :
(Long) savedInstanceState.getSerializable(GoalDbTable.KEY_ROWID);
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = (extras != null) ? extras.getLong(GoalDbTable.KEY_ROWID)
: null;
}
populateFields();
finishBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setResult(RESULT_OK);
finish();
}
});
}
private void populateFields() {
if (mRowId != null) {
Cursor goal = mDbGoals.find(mRowId);
startManagingCursor(goal);
mName.setText(goal.getString(
goal.getColumnIndexOrThrow(GoalDbTable.KEY_NAME)));
}
}
@Override
protected void onResume() {
super.onResume();
populateFields();
}
我觉得错误在于它找不到GoalEdit(尽管它显然可以)。我的代码中有没有明显的fubar(或者我应该检查的其他东西)?
编辑:
弄明白了如何更好地使用调试器,不得不再按几次resume来显示异常。
ERROR/AndroidRuntime(741):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.rossmasters.mygoals/com.rossmasters.mygoals.GoalEdit}:
java.lang.RuntimeException:
Binary XML file line #9: You must supply a layout_width attribute.
我不知道哪个文件是指,但是,我补充说
layout_width's
对每一个项目。