Konloch/bytecode-viewer · info · InputMismatchException
Only single character allowed
Error message
Only single character allowed
What it means
The character field handler throws InputMismatchException("Only single character allowed") when the field contains more than one character, since a char-sized (single-byte-slot) edit can only encode one character via codeArea.getCharset().
Source
Thrown at src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/ValuesPanel.java:606
{
showException(ex);
}
}
}//GEN-LAST:event_doubleTextFieldKeyReleased
private void characterTextFieldKeyReleased(java.awt.event.KeyEvent evt)
{//GEN-FIRST:event_characterTextFieldKeyReleased
if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable())
{
try
{
String characterText = characterTextField.getText();
if (characterText.length() == 0)
throw new InputMismatchException("Empty value not valid");
if (characterText.length() > 1)
throw new InputMismatchException("Only single character allowed");
byte[] bytes = characterText.getBytes(codeArea.getCharset());
System.arraycopy(bytes, 0, valuesCache, 0, bytes.length);
modifyValues(bytes.length);
updateValues();
}
catch (InputMismatchException ex)
{
showException(ex);
}
}
}//GEN-LAST:event_characterTextFieldKeyReleased
private void stringTextFieldKeyReleased(java.awt.event.KeyEvent evt)
{//GEN-FIRST:event_stringTextFieldKeyReleased
if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable())
{View on GitHub (pinned to 31430e0033)
Solutions
- Keep only one character in the field (delete the extra ones).
- Use the string field instead for multi-character input.
- Paste a single character, or paste into the string field which accepts longer text up to the cache size.
Example fix
// before
characterTextField.setText("AB"); // throws
// after
characterTextField.setText("A"); // or stringTextField.setText("AB"); Defensive patterns
Strategy: validation
Try / catch
try {
applyCharacterValue(characterTextField.getText());
} catch (InputMismatchException e) {
setStatus("Enter exactly one character (use the string field for longer text)");
} Prevention
- Enforce a 1-char DocumentFilter on the character field.
- Send multi-character input to the string field instead.
- Handle paste events by truncating or redirecting to the string field.
When it happens
Trigger: characterTextFieldKeyReleased with characterText.length() > 1 — pasting multi-character text or typing a second character into the field.
Common situations: Pasting a word or multi-byte sequence into the character field; IME composition leaving multiple chars; intending a string edit but using the character field.
Related errors
AI-assisted analysis of Konloch/bytecode-viewer@31430e0033 (2026-09-05).
Data as JSON: /api/errors/a3ce28e078c83b54.
Report an issue: GitHub.