Java Android上的startActivity(intent)不工作
因此,我试图通过序列化传递一些信息,但由于某些原因,它不起作用,我编写了两个Java Android上的startActivity(intent)不工作,java,android,android-intent,Java,Android,Android Intent,因此,我试图通过序列化传递一些信息,但由于某些原因,它不起作用,我编写了两个Log.e()用于测试,根据LogCat它说它没有通过startactivity(intent) 这是我的密码 public class MainActivity extends Activity { FileManager file = new FileManager(); FileInputStream fileInput; FileOutputStream fileOutput;
Log.e()
用于测试,根据LogCat
它说它没有通过startactivity(intent)
这是我的密码
public class MainActivity extends Activity {
FileManager file = new FileManager();
FileInputStream fileInput;
FileOutputStream fileOutput;
SortedArrayList<Contact> contactList = new SortedArrayList<Contact>();
ArrayList<Contact> theList =new ArrayList<Contact>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
fileInput = openFileInput("contacts.txt");
Log.e("FILE INPUT","FOUND!!");
contactList = file.read(fileInput,getApplicationContext());
Log.e("_____",contactList.toString());
}
catch (Exception e) {
Log.e("Error","ERROR CREATING FILE");
}
if(contactList.size() != 0){
ListView lv =(ListView)findViewById(R.id.contactList);
for(int i=0;i<contactList.size();i++){
theList.add(contactList.get(i));
}
ArrayAdapter<Contact> adapter = new MyListAdapter();
lv.setAdapter(adapter);
clickOnContact();
}
// Create The Adapter with passing ArrayList as 3rd parameter
//OrderAdapter arrayAdapter = new OrderAdapter(this, R.layout.list_view, contactListNameView, contactListLastNameView, contactListCellphoneView);
//Set The Adapter
//lv.setAdapter(arrayAdapter);
}
private void clickOnContact() {
ListView list = (ListView) findViewById(R.id.contactList);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int pos,
long id) {
Contact Contact = theList.get(pos);
Log.e("contact: ",Contact.getFirstName());
try{
Intent intent = new Intent(MainActivity.this, ShowContactActivity.class);
Log.e("pass ","1");
intent.putExtra("Contact",Contact);
Log.e("pass ","2");
startActivity(intent);
}
catch (Exception e){
Log.e("didnt","pass catch");
}
}
});
}
private class MyListAdapter extends ArrayAdapter<Contact> {
public MyListAdapter() {
super(MainActivity.this, R.layout.list_view, theList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if(itemView == null){
itemView = getLayoutInflater().inflate(R.layout.list_view, parent, false);
}
Contact contact = theList.get(position);
//Fill First Name
TextView name = (TextView) itemView.findViewById(R.id.contactName);
name.setText(contact.getFirstName());
//Fill Last Name
TextView lastname = (TextView) itemView.findViewById(R.id.contactLastName);
lastname.setText(contact.getLastName());
return itemView;
}
}
像
Contact contact = theList.get(pos); //contact is the object of the class (small c)
查看
Contact Contact=list.get(pos)代码>。出什么事了?为对象使用不同的名称(至少是小写字母)。只是这样做了,不会出现相同的错误…@user2896762也在此处更改它。。!!意向。额外(“联系”,联系);只是修复了它,我不知道ArrayList没有实现Serializable,所以我使用了我构建的数据结构,它工作了@用户2896762:好的。如果我的回答对你有帮助,请接受
Contact contact = theList.get(pos); //contact is the object of the class (small c)