簡體   English   中英

解組Java時發生異常

[英]Exception while unmarshalling Java

喂! 請幫我解決線程“ main”中的異常java.lang.InternalError:保存生成文件的I / O異常:java.io.FileNotFoundException:com \\ sun \\ proxy \\ $ Proxy0.class我需要使用以下類來解組該類屬性正確。

這是我的課堂實現

@XmlRootElement( name = "mail_settings_document" )
@XmlType(propOrder = { "senderMail", "SMTPHostServer" , "SMTPPort" , "login" ,    "password" , "encryption"})
public class TMailDocument extends TDocument implements IMailDocument {


// --------------------- [ КОНСТРУКТОР КЛАССА ] -----------------------------------------------------------------------------------

public TMailDocument() {}

public TMailDocument( String path, IDocumentAction action ) { super( path, action ); }

// --------------------- [ КОНСТРУКТОР КЛАССА ] -----------------------------------------------------------------------------------



// --------------------- [ ПРИВАТНЫЕ ДАННЫЕ ] -------------------------------------------------------------------------------------

/**  святая святых - параметры почты
 */

@XmlElement(name = "SENDER_MAIL")
private String senderMail = "";

@XmlElement(name = "SMTP_SERVER")
private String SMTPHostServer = "";

@XmlElement(name = "SMTP_PORT")
private String SMTPPort = "";

@XmlElement(name = "LOGIN")
private String login = "";

@XmlElement(name = "PASSWORD")
private String password = "";


@XmlElement(name = "ENCRYPTION", type = ENCRYPTION_TYPE.class)
private ENCRYPTION_TYPE encryption = ENCRYPTION_TYPE.UNKNOWN;

// --------------------- [ ПРИВАТНЫЕ ДАННЫЕ ] -------------------------------------------------------------------------------------



// --------------------- [ ПУБЛИЧНЫЕ МЕТОДЫ КЛАССА ] ------------------------------------------------------------------------------

public String name() { return this.getClass().getSimpleName(); }


/**  геттеры и сеттеры параметров почты
 */


@Override
public String getSMTPHostServer() { return SMTPHostServer;  }

@Override
public String getSenderMail() { return senderMail; }

@Override
public String getSMTPPort() { return SMTPPort;  }

@Override
public String getLogin() { return login; }

@Override
public String getPassword() { return password; }

@Override
public ENCRYPTION_TYPE getEncryption() { return encryption; }




@Override
@XmlTransient
public IDocument setEncryption(ENCRYPTION_TYPE encryption) {
    if ( encryption != null ) { this.encryption = encryption; }
    return this;
}

@Override
@XmlTransient
public IDocument setSenderMail ( String from )
{
    if ( from != null ) { this.senderMail = from; }
    return this;
}

@Override
@XmlTransient
public IDocument setSMTPHostServer ( String host ) throws Exception
{
    if ( host!= null ) { SMTPHostServer = host; }
    return this;
}

@Override
@XmlTransient
public IDocument setSMTPPort ( String port ) throws Exception
{
    if ( port!= null ) { SMTPPort = port; }
    return this;
}

@Override
@XmlTransient
public IDocument setLogin ( String login ) throws Exception
{

    if ( login!= null ) { this.login  = login; }
    return this;

}

@Override
@XmlTransient
public IDocument setPassword ( String pass ) throws Exception
{
    if ( pass!= null ) { password  = pass; }
    return this;

}
}

和我的類接口:

 public interface IMailDocument {

/** перечисление:какой тип шифрования используется
 *  UNKNOWN - пустое значение
 *  SSL - SSl
 *  TLS - TLS
 *  NONE - без шифрования
 */
public enum ENCRYPTION_TYPE
{
    UNKNOWN,SSL,TLS,NONE;

    public boolean isUnknown()
    {
        return this.equals(UNKNOWN);
    }

};

// --------------------- [ ПУБЛИЧНЫЕ МЕТОДЫ КЛАССА ] ------------------------------------------------------------------------------

/** свойство:метод: получение сервера
 */
public String getSMTPHostServer();

/** свойство:метод: получение адреса отправителя
 */
public String getSenderMail();

/** свойство:метод: получение порта севрера
 */
public String getSMTPPort();

/** свойство:метод: получение логина
 */
public String getLogin();

/** свойство:метод: получение пароля
 */
public String getPassword();

/** свойство:метод: тип шифрвоания подключения
 */
public TMailDocument.ENCRYPTION_TYPE getEncryption();

/** метод: устанвока шифрования
 */
public IDocument setEncryption(ENCRYPTION_TYPE encryption);

/** метод: устанвока почты отпраивтеля
 */
public IDocument setSenderMail ( String from );

/** метод: установка сервера
 */
public IDocument setSMTPHostServer ( String host ) throws Exception;

/** метод: установка порта севрера
 */
public IDocument setSMTPPort ( String port ) throws Exception ;

/** метод: установка логина
 */
public IDocument setLogin ( String login ) throws Exception ;

/** метод: установка пароля
 */
public IDocument setPassword ( String pass ) throws Exception ;
} 

PS所有文件都在正確的路徑中,並且編組順利進行


Exception in thread "main" java.lang.InternalError: I/O exception saving generated file: java.io.FileNotFoundException: com\sun\proxy\$Proxy0.class (Системе не удается найти указанный путь)
    at sun.misc.ProxyGenerator$1.run(Unknown Source)
    at sun.misc.ProxyGenerator$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.misc.ProxyGenerator.generateProxyClass(Unknown Source)
    at java.lang.reflect.Proxy.getProxyClass0(Unknown Source)
    at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.annotationForMap(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(Unknown Source)
    at java.lang.Class.initAnnotationsIfNecessary(Unknown Source)
    at java.lang.Class.getAnnotation(Unknown Source)
    at sun.reflect.annotation.AnnotationType.<init>(Unknown Source)
    at sun.reflect.annotation.AnnotationType.getInstance(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Unknown Source)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(Unknown Source)
    at java.lang.Class.initAnnotationsIfNecessary(Unknown Source)
    at java.lang.Class.getAnnotation(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader.getClassAnnotation(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader.getClassAnnotation(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at XDocumentFactory.XMLDocumentIO.loadXML(XMLDocumentIO.java:146)
    at XDocumentFactory.DocumentLoader.loadDocument(DocumentLoader.java:62)
    at XDocumentFactory.DocumentFactory.loadDocument(DocumentFactory.java:89)
    at XMailMessanger.MailMessenger.loadSettings(MailMessenger.java:158)
    at alfa.runner.main(runner.java:24)
-Dsun.misc.ProxyGenerator.saveGeneratedFiles=false

要么

try {
  final Field field = ProxyGenerator.class.getDeclaredField("saveGeneratedFiles");
  final boolean isAccessible = field.isAccessible();
  if (!isAccessible)
    field.setAccessible(true);
  final Field modifiers = field.getClass().getDeclaredField("modifiers");
  modifiers.setAccessible(true);
  modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
  modifiers.setAccessible(false);
  field.setBoolean(null, false);
  if (!isAccessible)
    field.setAccessible(false);
} catch (NoSuchFieldException | IllegalAccessException e) {
  e.printStackTrace();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM