开发者

Android Unknown Application Crash

I am trying to make an email client, whenever I try to run the application it crashes with the default message. Can any one please tell me where I am going wrong. Below are my Java files and manifest .

EmailManager.java

public class EmailManager {



    private String stmpHost = "smtp.gmail.com";
        private String mailServer = "imap.gmail.com";
        private EmailAccount account;
        private Session smtpSession; 
        private Session imapSession; 
        private Folder inbox;
        private Store store;



        public EmailManager(String username, String password, String urlServer, String stmpHost, String mailServer) {
            account = new EmailAccount(username, password, urlServer);
            this.stmpHost = stmpHost;
            this.mailServer = mailServer;
            initProtocol();
        }
        private void initProtocol() {
            EmailAuthenticator authenticator = new EmailAuthenticator(account);

            Properties props1 = new Properties();  
            props1.setProperty("mail.transport.protocol", "smtps");  
            props1.setProperty("mail.host", stmpHost);  
            props1.put("mail.smtp.auth", "true");  
            props1.put("mail.smtp.port", "465");  
            props1.put("mail.smtp.socketFactory.port", "465");  
            props1.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");  
            props1.put("mail.smtp.socketFactory.fallback", "false");  
            props1.setProperty("mail.smtp.quitwait", "false");  
            smtpSession = Session.getDefaultInstance(props1, authenticator); 

            Properties props2 = new Properties();
            props2.setProperty("mail.store.protocol", "imaps");
            props2.setProperty("mail.imaps.host", mailServer);
            props2.setProperty("mail.imaps.port", "993");
            props2.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props2.setProperty("mail.imaps.socketFactory.fallback", "false");
            imapSession = Session.getInstance(props2);
        }   
        public Message[] getMails() throws MessagingException {
            store = imapSession.getStore("imaps");
            store.connect(mailServer, account.username, account.password);
            inbox = store.getFolder("Inbox");
            inbox.open(Folder.READ_ONLY);
            Message[] result = inbox.getMessages();

            for (int i=0, n=result.length; i<n; i++) {
                   System.out.println(i + ": " + result[i].getFrom()[0] 
                     + "\t" + result[i].getSubject());


        }
            return result;
        }   
        public void close() {
            //Close connection 
            try {
                inbox.close(false);
                store.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       
        }
        public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {  
            MimeMessage message = new MimeMessage(smtpSession);
            DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));  
            message.setSender(new InternetAddress(sender));  
            message.setSubject(subject);  
            message.setDataHandler(handler);  
            if (recipients.indexOf(',') > 0)  
                message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));  
            else  
                message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));  
            Transport.send(message);  


            }
        } 

this email manager is called in mainactivity.java to run it

    public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        startActivity(new Intent(MainActivity.this, EmailManager.class));
    } 

}

Below is my Android manifest file.

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mailtest.android"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission
        android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".EmailManager"
                  android:label="@string/app_name" android:permission="android.permission.INTERNET">
        </activity>
        <activity android:name=".EmailAithenticator"
                  android:label="@string/app_name">
        </activity>
        <activity android:name=".EmailAccount"
                  android:label="@string/app_name">
        </activity>
        <activity android:name=".ByteArrayDataSource"
                  android:label="@string/app_name">
        </activity>

    </application>
</manifest>

The Log Cat had the following errors in red:

07-08 07:03:03.947: DEBUG/WifiService(1329): enable and start wifi due to updateWifiState 07-08 07:54:34.047: ERROR/UrlDrawable(1454): getInputStream failed! https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/276968_73855584817_8241940_q.jpg 07-08 07:54:34.047: ERROR/UrlDrawable(1454): java.net.UnknownHostException: fbcdn-profile开发者_如何学运维-a.akamaihd.net 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.net.InetAddress.lookupHostByName(InetAddress.java:500) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:297) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.net.InetAddress.getAllByName(InetAddress.java:256) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable.getInputStream(UrlDrawable.java:956) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable.getFromRemote(UrlDrawable.java:983) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable.access$800(UrlDrawable.java:71) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable$WorkerCallable.call(UrlDrawable.java:776) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable$WorkerCallable.call(UrlDrawable.java:710) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 07-08 07:54:34.047: ERROR/UrlDrawable(1454): at java.lang.Thread.run(Thread.java:1027) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): getInputStream failed! https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/276968_73855584817_8241940_q.jpg 07-08 07:54:34.057: ERROR/UrlDrawable(1454): java.net.UnknownHostException: fbcdn-profile-a.akamaihd.net 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.net.InetAddress.lookupHostByName(InetAddress.java:500) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:297) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.net.InetAddress.getAllByName(InetAddress.java:256) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable.getInputStream(UrlDrawable.java:956) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable.getFromRemote(UrlDrawable.java:984) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable.access$800(UrlDrawable.java:71) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable$WorkerCallable.call(UrlDrawable.java:776) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at com.htc.graphics.drawable.UrlDrawable$WorkerCallable.call(UrlDrawable.java:710) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 07-08 07:54:34.057: ERROR/UrlDrawable(1454): at java.lang.Thread.run(Thread.java:1027) 07-08 07:55:32.157: WARN/ResourceType(1537): Failure getting entry for 0x7f02027e (t=1 e=638) in package 0 (error -2147483647) 07-08 07:55:32.157: WARN/ResourceType(1537): getEntry failing because entryIndex 335 is beyond type entryCount 123 07-08 07:55:32.157: WARN/ResourceType(1537): Failure getting entry for 0x7f02014f (t=1 e=335) in package 0 (error -2147483647) 07-08 07:55:32.167: WARN/ResourceType(1537): getEntry failing because entryIndex 187 is beyond type entryCount 123 07-08 07:55:32.167: WARN/ResourceType(1537): Failure getting entry for 0x7f0200bb (t=1 e=187) in package 0 (error -2147483647) 07-08 07:55:32.177: WARN/ResourceType(1537): getEntry failing because entryIndex 638 is beyond type entryCount 123 07-08 07:55:32.177: WARN/ResourceType(1537): Failure getting entry for 0x7f02027e (t=1 e=638) in package 0 (error -2147483647) 07-08 07:55:32.177: WARN/ResourceType(1537): getEntry failing because entryIndex 335 is beyond type entryCount 123 07-08 07:55:32.177: WARN/ResourceType(1537): Failure getting entry for 0x7f02014f (t=1 e=335) in package 0 (error -2147483647) 07-08 07:55:32.177: WARN/ResourceType(1537): getEntry failing because entryIndex 187 is beyond type entryCount 123 07-08 07:55:32.177: WARN/ResourceType(1537): Failure getting entry for 0x7f0200bb (t=1 e=187) in package 0 (error -2147483647) 07-08 07:55:32.187: WARN/ResourceType(1537): getEntry failing because entryIndex 638 is beyond type entryCount 123


If your code above is correct then EmailManager is not an activity and you are calling

startActivity(new Intent(MainActivity.this, EmailManager.class));

As if it were one. Are you really trying to start another activity, or just instantiate a new class to be used by the main Activity?

As mentioned in the comments I suggest you actually give us the exception. Walking through (debugging) the code is your friend.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜