mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.27k stars 242 forks source link

ArrayIndexOutOfBoundsException #420

Closed Saint-Theana closed 5 years ago

Saint-Theana commented 5 years ago

i was trying to create a actionlistbox,I got following Exception;I think that hapened because length of itemtext was bigger than window's width.this also hapened when I tried to create a table.When I use shotter itemtext,this erro would not hapen.

java.lang.ArrayIndexOutOfBoundsException: 1 at com.googlecode.lanterna.gui2.GridLayout.shrinkWidthToFitArea(GridLayout.java:669) at com.googlecode.lanterna.gui2.GridLayout.doLayout(GridLayout.java:428) at com.googlecode.lanterna.gui2.Panel.layout(Panel.java:392) at com.googlecode.lanterna.gui2.Panel.access$300(Panel.java:38) at com.googlecode.lanterna.gui2.Panel$1.drawComponent(Panel.java:234) at com.googlecode.lanterna.gui2.Panel$1.drawComponent(Panel.java:221) at com.googlecode.lanterna.gui2.AbstractComponent.draw(AbstractComponent.java:218) at com.googlecode.lanterna.gui2.AbstractBasePane$ContentHolder$1.drawComponent(AbstractBasePane.java:340) at com.googlecode.lanterna.gui2.AbstractBasePane$ContentHolder$1.drawComponent(AbstractBasePane.java:324) at com.googlecode.lanterna.gui2.AbstractComponent.draw(AbstractComponent.java:218) at com.googlecode.lanterna.gui2.AbstractBasePane.draw(AbstractBasePane.java:73) at com.googlecode.lanterna.gui2.AbstractWindow.draw(AbstractWindow.java:128) at com.googlecode.lanterna.gui2.MultiWindowTextGUI.drawGUI(MultiWindowTextGUI.java:261) at com.googlecode.lanterna.gui2.AbstractTextGUI.updateScreen(AbstractTextGUI.java:120) at com.googlecode.lanterna.gui2.MultiWindowTextGUI.updateScreen(MultiWindowTextGUI.java:223) at com.googlecode.lanterna.gui2.AbstractTextGUIThread.processEventsAndUpdate(AbstractTextGUIThread.java:85) at com.googlecode.lanterna.gui2.MultiWindowTextGUI.waitForWindowToClose(MultiWindowTextGUI.java:409) at com.googlecode.lanterna.gui2.AbstractWindow.waitUntilClosed(AbstractWindow.java:269) at com.Tick_Tock.PCTIM.Main.main(Main.java:109)

mabe02 commented 5 years ago

Do you think you can provide a minimal code sample that reproduces this error? It's probably another bug in the GridLayout.

Saint-Theana commented 5 years ago

here is the bug sample: https://github.com/Saint-Theana/lanterna_learn

mabe02 commented 5 years ago

Thanks, I've fixed the bug and pushed to the release branch.

You can work around it by changing your GridLayout to only one column since you only have one component: this.contentPanel = new Panel(new GridLayout(2)) -> this.contentPanel = new Panel(new GridLayout(1))

Also, I'd strongly recommend you start formatting your code using general java code style conventions.

Saint-Theana commented 5 years ago

thanks for your help,but this problem is still unsolved,long itemtext still cannot be shown normally in Table/ActionListBox.

Saint-Theana commented 5 years ago

about your concern about my java coding style,Im not a software developer,I treat programing as a hobit,I like it,but I don't like computer,my code was completely written with app AIDE on Android Phone.It not big deal for me that the codes I wrote was hard to read,sorry that cause you troubles.😃

mabe02 commented 5 years ago

Are you sure you ran with the latest release/3.0 branch code? I haven't created a new Maven release yet. The example you sent above worked for me with the latest snapshot code.

Saint-Theana commented 5 years ago

I clone'd the source code from this repo... and build the library myself. And there is one more trouble botherring me,I had to pack lanterna library class and my Project class into one jar,or the terminal cannot run. I will try the 3.0.0 release on maven.

Saint-Theana commented 5 years ago

Table seems fine on release 3.0.0 .

avl42 commented 5 years ago

I'm not a maven expert, but rather than merging lanterna with your code (which might also be problematic with lanterna's LGPL, unless your code is (L)GPL as well), you might rather try to tell maven that your project simply depends on lanterna, and let maven sort out the details...

avl42 commented 5 years ago

maybe, being more verbose on "or the terminal cannot run" could also help ;-)