Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Coding beim wegschreiben von Properties-Objekt

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich habe folgendes Problem:

Ich habe ein Properties-Objekt (werte) als private Klassenvariable. In diesem Properties-Objekt, kann der Benutzer Schlüssel-Werte-Paare speichern. Blöderweise aber auch Sonderzeichen - und ich habe auch nicht vor diese MANUELL wegzuparsen. Deshalb gib ich beim wegspeichern (in einen XML-String) das Encoding UTF-8 mit. Wenn ich aber testweise in meiner Oberfläche ein Schlüssel-Werte-Paar in meinem werte Objekt mit einem € Zeichen wegspeichern möchte, bekomm ich eine ParseException.


try {

	ByteArrayOutputStream bo = new ByteArrayOutputStream();

	werte.storeToXML(bo, "", "UTF-8");

	wertestrg = bo.toString();

    } catch ( Exception x) { }

Das ist meine Exception:

java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException: Character conversion error: "Malformed UTF-8 char -- is an XML encoding declaration missing?" (line number may be too low).

at java.util.XMLUtils.load(Unknown Source)

at java.util.Properties.loadFromXML(Unknown Source)

at plugin.sendeplan.daf.db.Event.fill(Event.java:140)

at plugin.sendeplan.daf.db.Event.<init>(Event.java:115)

at plugin.sendeplan.daf.db.Event.fill(Event.java:146)

at plugin.sendeplan.daf.db.Event.<init>(Event.java:115)

at plugin.sendeplan.daf.db.Event.getAllByBeitragID(Event.java:297)

at plugin.sendeplan.daf.db.Event.getAllByBeitragID(Event.java:280)

at plugin.sendeplan.daf.gui.EventPanel.getAllEventsPanel(EventPanel.java:258)

at plugin.sendeplan.daf.gui.EventPanel.fill(EventPanel.java:128)

at plugin.sendeplan.daf.gui.EventPanel.save(EventPanel.java:533)

at plugin.sendeplan.InfoPane.save(InfoPane.java:935)

at plugin.sendeplan.Gui.save(Gui.java:4358)

at core.ApplicationFrame.action(ApplicationFrame.java:1006)

at core.ApplicationFrame.actionPerformed(ApplicationFrame.java:1688)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Caused by: org.xml.sax.SAXParseException: Character conversion error: "Malformed UTF-8 char -- is an XML encoding declaration missing?" (line number may be too low).

at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)

at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1072)

at org.apache.crimson.parser.InputEntity.isXmlDeclOrTextDeclPrefix(InputEntity.java:914)

at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:1009)

at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:486)

at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)

at java.util.XMLUtils.getLoadingDoc(Unknown Source)

... 41 more

Meine Frage:

Wie kann ich diese Exception umgehen ohne dass ich meine Schlüssel-Werte-Paare einzeln überprüfen muss? Ich glaube, dass er das Encoding noch nicht richtig nimmt ...

Ich hoffe, ihr könnt mir helfen!

Viele Grüße

UTF-8 und das Eurozeichen mögen sich nicht.

Entweder du nimmst ein ISO Encoding oder wirfst alle Währungen bei den Werten weg und sagst dann per weitere Property <CURRENCY>EUR</CURRENCY> und wertest das aus. Denn spätestens wenn die Daten in eine Datenbank sollen klappts mit der WÄhrung nicht mehr. Mach dir die Mühe und trenne Währung und Werte.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.