有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

所以我又问了另一个问题,我的邮件发送人每次发送邮件时都会在哪里出错。事实证明,简单的解决方案是没有声明特定导入的类定义。因此,我确保我的类路径中有jar,将其添加为库,并导入代码。然而,当我停止输入import语句时;它删除了自己。从技术上讲,它很快变成灰色,然后被删除。我试图通过使用不同的API来强制输入,然后在java studio中打开,但它会将其灰显,并在编译时删除。我现在不在安卓工作室的电脑前,但我不知道为什么它不能工作。其他人可以告诉我需要导入该类,但他们不知道为什么它会自动删除。谢谢你的帮助

活动文件:

package comi.coding.prometheus.ignisai;

import 安卓.annotation.SuppressLint;
import 安卓.content.Intent;
import 安卓.os.Bundle;
import 安卓.os.Handler;
import 安卓.support.v7.app.ActionBar;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.view.MotionEvent;
import 安卓.view.View;
import 安卓.widget.EditText;
import 安卓.widget.RelativeLayout;
import 安卓.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:安卓="http://schemas.安卓.com/apk/res/安卓"
        xmlns:tools="http://schemas.安卓.com/tools" 安卓:layout_width="match_parent"
        安卓:layout_height="match_parent" 安卓: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 安卓:id="@+id/fullscreen_content" 安卓:layout_width="match_parent"
            安卓:layout_height="match_parent" 安卓:keepScreenOn="true" 安卓:textColor="#33b5e5"
            安卓:textStyle="bold" 安卓:textSize="50sp" 安卓:gravity="center"
            安卓:layout_alignParentLeft="true"
            安卓:layout_marginLeft="0dp"
            安卓:layout_alignParentTop="true"
            安卓:background="#000000" 安卓:orientation="horizontal"
            安卓:layout_marginTop="0dp" />

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

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

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

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

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

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

        </RelativeLayout>

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

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

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

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

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

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

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

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

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

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

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

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

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


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



   </RelativeLayout>

清单Xml

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

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

    <application
        安卓:allowBackup="true"
        安卓:icon="@mipmap/ic_launcher"
        安卓:label="@string/app_name"
        安卓:theme="@style/AppTheme" >
        <activity
            安卓:name=".Main"
            安卓:label="@string/app_name" >
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <activity 安卓:name=".Browser"/>
        <activity 安卓: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个小错误, 99只小虫子。 找到一个, 修补一下, 代码中有127个小错误


共 (1) 个答案

  1. # 1 楼答案

    导入正在消失,因为您在Android Studio中启用了动态优化导入。您可以在设置中禁用/启用该功能>;编辑>;通用>;自动导入。正在生成NoClassDefFoundError异常,因为javax.activation.DataHandler在Android中不存在