diff --git a/src/com/strongjoshua/console/ConsoleContext.java b/src/com/strongjoshua/console/ConsoleContext.java index e95f3de..3438724 100644 --- a/src/com/strongjoshua/console/ConsoleContext.java +++ b/src/com/strongjoshua/console/ConsoleContext.java @@ -10,6 +10,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.badlogic.gdx.utils.reflect.ClassReflection; public class ConsoleContext { private Table root; @@ -18,15 +19,17 @@ public class ConsoleContext { ConsoleContext (Class tableClass, Class labelClass, Skin skin, String background) { try { - root = tableClass.newInstance(); + root = ClassReflection.newInstance(tableClass); } catch (Exception e) { throw new RuntimeException("Table class does not support empty constructor."); } try { - copy = labelClass.getConstructor(CharSequence.class, Skin.class).newInstance("Copy", skin); + copy = (Label) ClassReflection.getConstructor(labelClass, CharSequence.class, Skin.class) + .newInstance("Copy", skin); } catch (Exception e) { try { - copy = labelClass.getConstructor(CharSequence.class).newInstance("Copy"); + copy = (Label) ClassReflection.getConstructor(labelClass, CharSequence.class) + .newInstance("Copy"); } catch (Exception e2) { throw new RuntimeException( "Label class does not support either (, ) or () constructors."); diff --git a/src/com/strongjoshua/console/ConsoleUtils.java b/src/com/strongjoshua/console/ConsoleUtils.java index 946f90e..cf59191 100644 --- a/src/com/strongjoshua/console/ConsoleUtils.java +++ b/src/com/strongjoshua/console/ConsoleUtils.java @@ -33,12 +33,10 @@ public static String exceptionToString (final Throwable throwable) { Throwable cause = throwable; while (cause != null) { - if (result.length() == 0) { - result.append("\nException in thread \"").append(Thread.currentThread().getName()).append("\" "); - } else { - result.append("\nCaused by: "); - } - result.append(cause.getClass().getCanonicalName()).append(": ").append(cause.getMessage()); + result.append("\nCaused by: ") + .append(cause.getClass().getCanonicalName()) + .append(": ") + .append(cause.getMessage()); for (final StackTraceElement traceElement : cause.getStackTrace()) { result.append("\n\tat ").append(traceElement.toString()); diff --git a/src/com/strongjoshua/console/GUIConsole.java b/src/com/strongjoshua/console/GUIConsole.java index 78af05d..6265c52 100644 --- a/src/com/strongjoshua/console/GUIConsole.java +++ b/src/com/strongjoshua/console/GUIConsole.java @@ -30,6 +30,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.SnapshotArray; +import com.badlogic.gdx.utils.reflect.ClassReflection; /** * A simple console that allows live logging, and live execution of methods, from within an application. Please see the , ) or () constructors."); } @@ -410,7 +413,7 @@ private class ConsoleDisplay { ConsoleDisplay (Skin skin) { try { - root = tableClass.newInstance(); + root = ClassReflection.newInstance(tableClass); } catch (Exception e) { throw new RuntimeException("Table class does not support empty constructor."); } @@ -428,23 +431,26 @@ private class ConsoleDisplay { labels = new Array