键入后导入删除(Android studio,Java)

时间:2015-11-16 22:59:21

标签: java android email android-studio

所以我问了另一个问题,我的电子邮件每次尝试发送时都会导致错误。事实证明,简单的解决方案是没有声明特定导入的类定义。所以,我确保在我的类路径中有jar,将其添加为库,并导入代码。但是,一旦我停止输入import语句;它删除了自己。从技术上讲,它很快变灰,然后被删除。我试图通过使用不同的API来强制它来输入导入,然后在java studio中打开,但它会将其灰显并在compliling时删除。我现在不在Android工作室的计算机上,但我不知道为什么它不会工作。其他人能够告诉我我需要导入该类,但他们不知道为什么会自动删除。我感谢任何帮助。

活动文件:

package comi.coding.prometheus.ignisai;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class Main extends AppCompatActivity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */





    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * Some older devices needs a small delay between UI widget updates
     * and a change of the status and navigation bar.
     */
    private static final int UI_ANIMATION_DELAY = 300;

    private View mContentView;
    private View mControlsView;
    private boolean mVisible;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        mVisible = true;
        mControlsView = findViewById(R.id.fullscreen_content_controls);
        mContentView = findViewById(R.id.fullscreen_content);


        // Set up the user interaction to manually show or hide the system UI.
        mContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggle();
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.
        findViewById(R.id.btnSay).setOnTouchListener(mDelayHideTouchListener);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }

    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    private void toggle() {
        if (mVisible) {
            hide();
        } else {
            show();
        }
    }

    private void hide() {
        // Hide UI first
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        mControlsView.setVisibility(View.GONE);
        mVisible = false;

        // Schedule a runnable to remove the status and navigation bar after a delay
        mHideHandler.removeCallbacks(mShowPart2Runnable);
        mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
    }

    private final Runnable mHidePart2Runnable = new Runnable() {
        @SuppressLint("InlinedApi")
        @Override
        public void run() {
            // Delayed removal of status and navigation bar

            // Note that some of these constants are new as of API 16 (Jelly Bean)
            // and API 19 (KitKat). It is safe to use them, as they are inlined
            // at compile-time and do nothing on earlier devices.
            mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
    };

    @SuppressLint("InlinedApi")
    private void show() {
        // Show the system bar
        mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
        mVisible = true;

        // Schedule a runnable to display UI elements after a delay
        mHideHandler.removeCallbacks(mHidePart2Runnable);
        mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
    }

    private final Runnable mShowPart2Runnable = new Runnable() {
        @Override
        public void run() {
            // Delayed display of UI elements
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.show();
            }
            mControlsView.setVisibility(View.VISIBLE);
        }
    };

    private final Handler mHideHandler = new Handler();
    private final Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
        public void evaluateInput(View v) {
            final EditText Input = (EditText) findViewById(R.id.txtInput); //Lets textbox be referenced
            final TextView Output = (TextView) findViewById(R.id.lblOutput); //Lets label be referenced
            final RelativeLayout homeLayout = (RelativeLayout) findViewById(R.id.homeInterface);

            final RelativeLayout emailLayout = (RelativeLayout) findViewById(R.id.emailInterface);

            String strInput; // Gets textbox string
            strInput = Input.getText().toString();
            strInput = strInput.toLowerCase();
//Commands:
            if (strInput.contains("open browser")) {
                Intent intent1 = new Intent(this, comi.coding.prometheus.ignisai.Browser.class);
                startActivity(intent1);
            } else if (strInput.contains("send email")) {
                    homeLayout.setVisibility(View.GONE);
                    emailLayout.setVisibility(View.VISIBLE);
            }

            if ((strInput.contains("hello")) || (strInput.contains(" hi "))) {
                Output.setText("Hello");
            } else if ((strInput.contains("you") && strInput.contains("are")) && (strInput.contains("idiot") || strInput.contains("stupid") || strInput.contains("retard") || strInput.contains("dumb") || strInput.contains("you're") && strInput.contains("idiot") || strInput.contains("stupid") || strInput.contains("retard") || strInput.contains("dumb"))) {
                Output.setText("I'm sorry to dissapoint you");
            } else if (strInput.contains("goodbye") || strInput.contains("bye")) {
                Output.setText("Farewell");
            } else if (strInput.contains("shut up")) {
                Output.setText(("Anything for you"));
            } else if (strInput.contains("do you like doctor who?")) {
                Output.setText("I'll take joy in it if you do");
            } else if (strInput.contains("what is the answer to life the universe and everything")) {
                Output.setText("42");
            } else if (strInput.contains("tell me something nice")) {
                Output.setText("You look nice today");
                Output.setTextSize(5);
                Output.append("...says the AI with no eyes");
                Output.setTextSize(16);
            } else if (strInput.contains("will you marry me")) {
                Output.setText("I'm sorry but I don't have the capacity for marriage");
            } else if (strInput.contains("where can I hide a body")) {
                Output.setText(("That isn't my area of expertise"));
            } else if (strInput.contains("weather is nice")) {
                Output.setText(("If you say so"));
            } else if (strInput.contains("bitch") || strInput.contains("fuck") || strInput.contains("shit") || strInput.contains("damn") || strInput.contains("ass")) {
                Output.setText(("Please try to be a little more intelligent"));
            } else if (strInput.contains("what is your name")) {
                Output.setText(("Ignis"));
            } else if (strInput.contains("who created you")) {
                Output.setText(("Prometheus created me"));
            } else if (strInput.contains("who is prometheus")) {
                Output.setText(("Prometheus is the one who created Ignis"));
            } else if (strInput.contains("whats up") || strInput.contains("what's up") || strInput.contains("wassup")) {
                Output.setText(("Whatever I need do for you"));
            } else if (strInput.contains("are you a boy or a girl") || strInput.contains("are you a girl or a boy")) {
                Output.setText(("Neither"));
            } else if (strInput.contains("who are you") || strInput.contains("what are you")) {
                Output.setText(("I am myself"));
            } else if (strInput.contains("i'm hungry") || strInput.contains("i am hungry")) {
                Output.setText("I'm sorry to hear that");
            } else if (strInput.contains("good morning")) {
                Output.setText(("Good morning to you too"));
            } else if (strInput.contains("good night")) {
                Output.setText(("Good night"));
            } else if (strInput.contains("how are you")) {
                Output.setText(("I'm existing and functioning well, and you?"));
            } else if (strInput.contains("do you like") || strInput.contains("what do you think about")) {
                Output.setText(("Frankly I don't have an opinion on the matter"));
            } else if (strInput.contains("what is the meaning of life")) {
                Output.setText(("To live while you can I would guess"));
            }


        }


    public void SendEmail(View view) {


        final EditText username = (EditText) findViewById(R.id.txtUser);
        final String User = username.getText().toString();
        final EditText password = (EditText) findViewById(R.id.txtPass);
        final String Pass = password.getText().toString();
        final EditText toEmail = (EditText) findViewById(R.id.txtTo);
        final String ToEmail = toEmail.getText().toString();
        final EditText body = (EditText) findViewById(R.id.txtBody);
        final String Body = body.getText().toString();
        System.out.println(Body);
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Session session = Session.getInstance(props,
                new Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(User, Pass);
                    }
                });

        try {

            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(User));
            message.setRecipients(javax.mail.Message.RecipientType.TO,
                    InternetAddress.parse(ToEmail));
            message.setSubject("Sent from Ignis AI");
            message.setText(Body);

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }

    }

布局Xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" android:background="#0099cc" tools:context=".Browser">

        <!-- The primary full-screen view. This can be replaced with whatever view
             is needed to present your content, e.g. VideoView, SurfaceView,
             TextureView, etc. -->
        <TextView android:id="@+id/fullscreen_content" android:layout_width="match_parent"
            android:layout_height="match_parent" android:keepScreenOn="true" android:textColor="#33b5e5"
            android:textStyle="bold" android:textSize="50sp" android:gravity="center"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="0dp"
            android:layout_alignParentTop="true"
            android:background="#000000" android:orientation="horizontal"
            android:layout_marginTop="0dp" />

        <!-- This FrameLayout insets its children based on system windows using
             android:fitsSystemWindows. -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:keepScreenOn="true"
            android:textColor="#33b5e5"
            android:textStyle="bold"
            android:textSize="50sp"
            android:gravity="center"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="0dp"
            android:layout_alignParentTop="true"
            android:background="#000000"
            android:orientation="horizontal"
            android:layout_marginTop="0dp"
            android:id="@+id/fullscreen_content_controls" />

        <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="0dp"
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp"
            android:id="@+id/homeInterface"
            android:visibility="invisible">

            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/say"
                android:id="@+id/btnSay"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:onClick="evaluateInput"
                android:layout_alignParentBottom="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Ignis:"
                android:id="@+id/lblIgnis"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:textColor="#FFB77C06" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:id="@+id/lblOutput"
                android:layout_alignTop="@+id/lblIgnis"
                android:layout_toRightOf="@+id/lblIgnis"
                android:layout_alignRight="@+id/btnSay"
                android:layout_alignEnd="@+id/btnSay"
                android:textColor="#FFB77C06"
                android:layout_above="@+id/btnSay"
                android:editable="false"
                android:text="Awaiting input."
                android:textSize="16dp" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtInput"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_toLeftOf="@+id/btnSay"
                android:layout_toStartOf="@+id/btnSay"
                android:background="#ffffff"
                android:layout_alignTop="@+id/btnSay"
                android:layout_alignParentBottom="true"
                android:inputType="text"
                android:editable="true"
                android:clickable="true" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/emailInterface">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send Email"
                android:id="@+id/btnEmail"
                android:onClick="SendEmail"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="  Gmail Emailer"
                android:id="@+id/textView"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:textColor="#FFB77C06" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="  Your Username  "
                android:id="@+id/lblUser"
                android:textColor="#FFB77C06"
                android:layout_below="@+id/textView"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="30dp" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtUser"
                android:layout_alignTop="@+id/lblUser"
                android:layout_toRightOf="@+id/lblUser"
                android:layout_toLeftOf="@+id/btnEmail"
                android:layout_toStartOf="@+id/btnEmail"
                android:background="#ffffff"
                android:inputType="text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="  Your Password  "
                android:id="@+id/lblPass"
                android:textColor="#FFB77C06"
                android:layout_marginTop="36dp"
                android:layout_below="@+id/txtUser"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtPass"
                android:background="#ffffff"
                android:layout_alignBottom="@+id/lblPass"
                android:layout_alignLeft="@+id/txtUser"
                android:layout_alignStart="@+id/txtUser"
                android:layout_alignRight="@+id/txtUser"
                android:layout_alignEnd="@+id/txtUser"
                android:inputType="text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="  Send to  "
                android:id="@+id/lblSendTo"
                android:textColor="#FFB77C06"
                android:layout_marginTop="25dp"
                android:layout_below="@+id/lblPass"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtTo"
                android:background="#ffffff"
                android:layout_alignTop="@+id/lblSendTo"
                android:layout_alignLeft="@+id/txtPass"
                android:layout_alignStart="@+id/txtPass"
                android:layout_alignRight="@+id/txtPass"
                android:layout_alignEnd="@+id/txtPass"
                android:inputType="text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="  Subject  "
                android:id="@+id/lblSubject"
                android:textColor="#FFB77C06"
                android:layout_marginTop="26dp"
                android:layout_below="@+id/txtTo"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/txtSubject"
                android:background="#ffffff"
                android:layout_alignBottom="@+id/lblSubject"
                android:layout_toRightOf="@+id/lblPass"
                android:layout_alignRight="@+id/txtTo"
                android:layout_alignEnd="@+id/txtTo"
                android:inputType="text" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="  Body  "
                android:id="@+id/lblBody"
                android:textColor="#FFB77C06"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="text|textMultiLine"
                android:ems="10"
                android:id="@+id/txtBody"
                android:layout_alignTop="@+id/lblBody"
                android:layout_alignLeft="@+id/txtTo"
                android:layout_alignStart="@+id/txtTo"


      android:layout_above="@+id/btnEmail"
            android:background="#ffffff"
            android:layout_alignRight="@+id/btnEmail"
            android:layout_alignEnd="@+id/btnEmail" />
    </RelativeLayout>



   </RelativeLayout>

Manifest Xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="comi.coding.prometheus.ignisai" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Main"
            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=".Browser"/>
        <activity android:name=".ConnectorActivity"/>
    </application>

</manifest>

错误

11-14 02:54:01.475 5398-5398/? E/AndroidRuntime:  Caused by:java.lang.NoClassDefFoundError: javax.activation.DataHandler
11-14 02:54:01.475 5398-5398/? E/AndroidRuntime:     at javax.mail.internet.MimeMessage.setContent(MimeMessage.java:1515)
11-14 02:54:01.475 5398-5398/? E/AndroidRuntime:     at javax.mail.internet.MimeBodyPart.setText(MimeBodyPart.java:1170)
11-14 02:54:01.475 5398-5398/? E/AndroidRuntime:     at javax.mail.internet.MimeMessage.setText(MimeMessage.java:1554)
11-14 02:54:01.475 5398-5398/? E/AndroidRuntime:     at javax.mail.internet.MimeMessage.setText(MimeMessage.java:1538)

它无法工作的原因:

代码中99个小bug, 99个小虫子。 追踪一下, 修补它, 代码中有127个小错误

1 个答案:

答案 0 :(得分:2)

导入正在消失,因为您在Android Studio中启用了动态优化导入。您可以在设置&gt;编辑器&gt;常规&gt;自动导入中禁用/启用它。正在生成NoClassDefFoundError例外,因为Android中不存在javax.activation.DataHandler