标题是我尝试将对象添加到arraylist时收到的错误
这是我的代码的开始,直到onCreate方法。我正在尝试使用一个按钮将“ TimeTableEntries”的对象添加到“ timetableItemsList” arraylist
*import statements*
public class Main extends AppCompatActivity {
TimetableEntriesClass timetableEntry;
private static final int Add_New_Item = Menu.FIRST;
private static final int Remove_Item = Menu.FIRST + 1;
private boolean addingNew = false;
private ListView timetableListView;
private EditText moduleCodeText;
private EditText DayOfWeekText;
private EditText StartTimeText;
private EditText DurationText;
private EditText SessionTypeText;
private EditText RoomText;
private Button Add;
private ArrayList<TimetableEntriesClass> timetableItemsList;
private TimetableEntriesAdapter aa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
timetableListView = (ListView)findViewById(R.id.myListView);
moduleCodeText = (EditText)findViewById(R.id.ModuleCode);
DayOfWeekText = (EditText)findViewById(R.id.DayOfWeek);
StartTimeText = (EditText)findViewById(R.id.StartTime);
DurationText = (EditText)findViewById(R.id.Duration);
SessionTypeText = (EditText)findViewById(R.id.SessionType);
RoomText = (EditText)findViewById(R.id.Room);
Add = (Button)findViewById(R.id.AddButton);
timetableItemsList = new ArrayList<TimetableEntriesClass>();
int resID = R.layout.timetable_view;
aa = new TimetableEntriesAdapter(this, resID, timetableItemsList);
timetableListView.setAdapter(aa);
Add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TimetableEntriesClass item = new TimetableEntriesClass(moduleCodeText.getText().toString(), DayOfWeekText.getText().toString(),
Integer.parseInt(StartTimeText.getText().toString() + ""), Integer.parseInt(DurationText.getText().toString() + ""),
SessionTypeText.getText().toString(), RoomText.getText().toString());
timetableItemsList.add(item);
aa.notifyDataSetChanged();
moduleCodeText.setText("@string/module_code");
DayOfWeekText.setText("@string/day_of_week");
StartTimeText.setText("@string/start_time");
DurationText.setText("@string/duration");
SessionTypeText.setText("@string/type_of_session");
RoomText.setText("@string/room");
}
});
registerForContextMenu(timetableListView);
}
04-04 15:19:11.499 2082-2119/com.example.daniel.mobileassignment E/Surface: getSlotFromBufferLocked: unknown buffer: 0xad2fefd0
04-04 15:19:13.523 2082-2082/com.example.daniel.mobileassignment W/ResourceType: No package identifier when getting value for resource number 0x00000001
04-04 15:19:13.532 2082-2082/com.example.daniel.mobileassignment D/AndroidRuntime: Shutting down VM
04-04 15:19:13.547 2082-2082/com.example.daniel.mobileassignment E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.daniel.mobileassignment, PID: 2082
android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.Resources.getText(Resources.java:312)
最佳答案
我发现了问题,它是我的ArrayAdapter中的setText,当它只需要一个int时,它正在寻找String资源ID!