我正在使用以下代码:
public class tets extends Activity implements OnClickListener,
android.view.View.OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
Store store = null;
Folder folder = null;
Message[] messages = null;
try {
store = session.getStore("imaps");
store.connect("imap.gmail.com","xxx@gmail.com", "xxx");
folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
messages = folder.getMessages();
Message Message[] = folder.getMessages();
FetchProfile fp = new FetchProfile();
folder.fetch(messages, fp);
} catch (MessagingException e) {
e.printStackTrace();
}
//System.out.println("Message Count "+folder.getMessageCount());
//System.out.println("New Message Count "+folder.getUnreadMessageCount());
//FetchProfile fp = new FetchProfile();
//fp.add(FetchProfile.Item.ENVELOPE);
//folder.fetch(messages, fp);
TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
for (int i = 0; i < messages.length; i++)
{
//System.out.println("From:"+ messages[i].getFrom());
TableRow row = new TableRow(this);
// create a new TextView
TextView number = new TextView(this);
number.setOnClickListener(this);
TextView country = new TextView(this);
number.setOnClickListener(this);
// set the text to "text xx"
try{
number.setText(messages[i].getDescription().toString());
}
catch(MessagingException e)
{
e.printStackTrace();
}
//country.setPadding(2, 1, 1, 1);
// add the TextView
row.addView(number);
row.addView(country);
// add the TableRow to the TableLayout
table.addView(row);
} try {
folder.close(true);
store.close();
} catch (MessagingException e) {
e.printStackTrace();
}
}
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("data", ((TextView) v).getText().toString());
Intent newIntent = new Intent(this.getApplicationContext(),
Details.class);
newIntent.putExtras(bundle);
startActivity(newIntent);
}
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setContentView(R.layout.main);
}
}
答案 0 :(得分:0)
似乎folder.getMessages()
提供null
值