1
更新:修正,這是由於缺少視圖屬性和我不知道如何工作的調試器:)啓動另一個活動將創建一個空白的屏幕和死機
我真的很新的到Android 。我剛完成了記事本教程,並且正在做類似的事情(大部分代碼完全相同)。事件的順序我經歷:
- 調試應用程序
- 單擊菜單,其中有正確的項目
- 單擊插入,打開一個新的活動(GoalEdit)
- 我打一個斷點在
GoalEdit.onCreate
的第一行,並得到以下警告:
a。 (ActivityManager)啓動超時已過,放棄喚醒鎖定! b。對於HistoryRecord {...} - (ActivityManager)活動空閒超時我在
setContentView
斷點在GoalEdit.onCreate
- 這是通過後:
一個。 ActivityThread.perfo:未找到源。
相關的代碼如下:
GoalsList.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(或其他我應該檢查的東西)?
編輯:找出如何更好地使用調試器,必須再按幾次繼續以顯示異常。
例外
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
到每個項目。
Ross啓用你的logcat,你將得到你的問題,窗口>顯示視圖>其他> Android> Logcat – Jorgesys 2010-07-28 18:14:20
Jorgesys:是的沒錯。看來問題是在視圖中缺少layout_width。認爲我需要閱讀一些關於使用Eclipse的調試器:) – Ross 2010-07-28 18:17:50
;)是在你的goal_edit中缺少屬性。xml佈局 – Jorgesys 2010-07-28 18:19:27