简体   繁体   English

java.awt.Choice.select(Choice.java:430)

[英]java.awt.Choice.select(Choice.java:430)

I work on image segmentation, this my code for Image choice 我致力于图像分割,这是我选择图像的代码

m_ImageChoice = new Choice();
for ( int i = 0; i < m_Images.size(); i++ )
  {
  m_ImageChoice.add( ( String ) m_Descriptions.get( i ) );
  }
m_ImageChoice.select( 0 );
m_ImageChoice.setBounds( 20, 270, 230, 30 );
m_ImageChoice.addItemListener( this );
add( m_ImageChoice );

but when I run the applet it throw Exception. 但是当我运行该applet时,它将引发Exception。

java.lang.IllegalArgumentException: illegal Choice item position: 0 at java.awt.Choice.select(Choice.java:430) java.lang.IllegalArgumentException:非法选择项位置:java.awt.Choice.select(Choice.java:430)为0

how can I fix it? 我该如何解决?

Read the Javadoc : 阅读Javadoc

Throws: 抛出:

IllegalArgumentException - if the specified position is greater than the number of items or less than zero IllegalArgumentException如果指定位置大于项目数或小于零

Your argument isn't less than zero, so it must be "greater than the number of items". 您的参数不小于零,因此它必须“大于项目数”。 If that's the case, m_Images.size() was zero. 如果是这样, m_Images.size()为零。

(Actually, there's a typo in the Javadoc here, it should say "greater than or equal to ", since that's the check in the code ) (实际上,这里的Javadoc中有一个错字,它应该说“大于或等于 ”,因为这是代码中的检查内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM