- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好吧,我仍然是一个 Java 新手。说实话,这是一份家庭作业,但我现在正在用头撞墙。我不知道从这里该去哪里。
我正在为作业编写一个库存程序,它必须使用普通数组。不是 ArrayList
我感到困惑的部分是您必须向数组添加新条目的部分。我通过使用 Arrays.copyof 创建它的第二个版本,然后将其重新复制到具有增强长度的原始版本来实现。它似乎有效,通过控制台我可以毫无问题地打印我的新数组,并完成新条目。我遇到的问题是我的 gui 的问题。每次我尝试在我的 gui 中显示新条目时,我都会得到
"Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5"
我确信我犯了一些愚蠢的错误,但我已经度过了漫长的一天,我完全被这个问题难住了。
package inventoryprogram3;
public class Inventoryprogram3 {
public static void main(String[] args) {
inventoryGui gui = new inventoryGui();
gui.setVisible(true);
}
}
package inventoryprogram3;
import java.io.Serializable;
class sItem implements Serializable{
int itemNumber;
String itemName;
int itemStock;
double itemPrice;
double stockTotal;
public sItem(int iNumber, String iName, int iStock, double iPrice){
itemNumber = iNumber;
itemName = iName;
itemStock = iStock;
itemPrice = iPrice;
}
}
public class rBook extends sItem {
int pCount;
double rFee;
public rBook(int iNumber, String iName, int iStock, double iPrice, int pageCount) {
super(iNumber, iName, iStock, iPrice);
pCount = pageCount;
rFee = (iPrice * iStock) * 1.05;
}
}
package inventoryprogram3;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
public class inventoryGui extends javax.swing.JFrame {
/**
* Creates new form inventoryGui
*/
static int max = 5;
static rBook[] rpg = new rBook[max];
double invValue;
int counter = -1;
public inventoryGui() {
initComponents();
rpg[0] = new rBook(1, "Mutants & Masterminds", 4, 19.99, 200);
rpg[1] = new rBook(2, "Exalted", 6, 25.99, 542);
rpg[2] = new rBook(3, "D&D Next", 15, 49.95, 350);
rpg[3] = new rBook(4, "Eclipse Phase", 3, 28.99, 426);
rpg[4] = new rBook(5, "The Mutant Epoch", 8, 19.99, 386);
}
private void initComponents() {
jLabel4 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
nameLabel = new javax.swing.JLabel();
titleLabel = new javax.swing.JLabel();
iNumberLabel = new javax.swing.JLabel();
priceLabel = new javax.swing.JLabel();
pCountlabel = new javax.swing.JLabel();
stockLabel = new javax.swing.JLabel();
restockLabel = new javax.swing.JLabel();
entireInventoryLabel = new javax.swing.JLabel();
restockField = new javax.swing.JTextField();
stockField = new javax.swing.JTextField();
pCountField = new javax.swing.JTextField();
priceField = new javax.swing.JTextField();
iNumberField = new javax.swing.JTextField();
titleField = new javax.swing.JTextField();
inventoryValueLabel = new javax.swing.JLabel();
inventoryValueField = new javax.swing.JTextField();
nextButton = new javax.swing.JButton();
entireInventoryField = new javax.swing.JTextField();
buttonLabel = new javax.swing.JLabel();
previousButton = new javax.swing.JButton();
companyLogo = new javax.swing.JLabel();
saveButton = new javax.swing.JButton();
loadButton = new javax.swing.JButton();
addbutton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
modifyButton = new javax.swing.JButton();
searchButton = new javax.swing.JButton();
jLabel4.setText("jLabel4");
jLabel2.setText("jLabel2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("RPG Inventory Program v0.4");
nameLabel.setText("Role Playing Game Inventory");
titleLabel.setText("Title");
iNumberLabel.setText("Item Number");
priceLabel.setText("Price");
pCountlabel.setText("Page Count");
stockLabel.setText("Copies in Stock");
restockLabel.setText("Restocking Fee");
entireInventoryLabel.setText("Value of Entire Inventory");
restockField.setEditable(false);
iNumberField.setEditable(false);
inventoryValueLabel.setText("Inventory Value");
nextButton.setText("Next");
nextButton.setToolTipText("Click toDisplay Next Item");
nextButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextButtonActionPerformed(evt);
}
});
entireInventoryField.setEditable(false);
buttonLabel.setText("Item Display");
previousButton.setText("Previous");
previousButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
previousButtonActionPerformed(evt);
}
});
companyLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/inventoryprogram3/logo4.png")));
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
loadButton.setText("Clear");
loadButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadButtonActionPerformed(evt);
}
});
addbutton.setText("Add");
addbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addbuttonActionPerformed(evt);
}
});
deleteButton.setText("Delete");
deleteButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteButtonActionPerformed(evt);
}
});
modifyButton.setText("Modify Current Item");
modifyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modifyButtonActionPerformed(evt);
}
});
searchButton.setText("Search");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pCountlabel)
.addGap(18, 18, 18)
.addComponent(pCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(entireInventoryLabel))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(restockLabel)
.addGap(192, 192, 192)
.addComponent(previousButton))
.addGroup(layout.createSequentialGroup()
.addComponent(loadButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addbutton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(deleteButton)
.addGap(18, 18, 18)
.addComponent(modifyButton)
.addGap(12, 12, 12)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(nextButton)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(saveButton))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(nameLabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(priceLabel)
.addGap(18, 18, 18)
.addComponent(priceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(titleLabel)
.addGap(18, 18, 18)
.addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(iNumberLabel)
.addGap(18, 18, 18)
.addComponent(iNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(searchButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(companyLogo)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(restockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(inventoryValueLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(inventoryValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(stockLabel)
.addGap(18, 18, 18)
.addComponent(stockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(entireInventoryField, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(buttonLabel)
.addGap(15, 15, 15)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {iNumberLabel, pCountlabel, priceLabel, restockLabel, stockLabel, titleLabel});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {iNumberField, inventoryValueField, pCountField, priceField, restockField, stockField, titleField});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(nameLabel)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(titleLabel)
.addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(searchButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(iNumberLabel)
.addComponent(iNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(priceLabel)
.addComponent(priceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(companyLogo, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pCountlabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(pCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(entireInventoryLabel)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(stockLabel)
.addComponent(stockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(entireInventoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(inventoryValueLabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(inventoryValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonLabel)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(restockLabel)
.addComponent(restockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(previousButton)
.addComponent(nextButton))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveButton)
.addComponent(addbutton)
.addComponent(deleteButton)
.addComponent(modifyButton)
.addComponent(loadButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(counter< max -1){
counter = counter + 1;
}
else{
counter = 0;
}
NumberFormat realMoney = NumberFormat.getCurrencyInstance(Locale.US);
invValue = 0;
for (int x=0; x < max -1; x++) {
invValue += rpg[x].itemStock * rpg[x].itemPrice;
}
System.out.println(counter);
titleField.setText(rpg[counter].itemName);
iNumberField.setText(String.valueOf(rpg[counter].itemNumber));
pCountField.setText(String.valueOf(rpg[counter].pCount));
priceField.setText(String.valueOf(realMoney.format(rpg[counter].itemPrice)));
stockField.setText(String.valueOf(rpg[counter].itemStock));
restockField.setText(String.valueOf(rpg[counter].rFee));
inventoryValueField.setText(String.valueOf(rpg[counter].itemStock * rpg[counter].itemPrice));
entireInventoryField.setText(String.valueOf(realMoney.format(invValue)));
}
private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(counter>= 1){
counter = counter - 1;
}
else{
counter = max -1;
}
NumberFormat realMoney = NumberFormat.getCurrencyInstance(Locale.US);
invValue = 0;
for (int x=0; x < max -1; x++) {
invValue += rpg[x].itemStock * rpg[x].itemPrice;
}
titleField.setText(rpg[counter].itemName);
iNumberField.setText(String.valueOf(rpg[counter].itemNumber));
pCountField.setText(String.valueOf(rpg[counter].pCount));
priceField.setText(String.valueOf(realMoney.format(rpg[counter].itemPrice)));
stockField.setText(String.valueOf(rpg[counter].itemStock));
restockField.setText(String.valueOf(rpg[counter].rFee));
inventoryValueField.setText(String.valueOf(rpg[counter].itemStock * rpg[counter].itemPrice));
entireInventoryField.setText(String.valueOf(realMoney.format(invValue)));
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
ObjectOutputStream savefile = null;
int dirmake = 1;
do{
try {
savefile = new ObjectOutputStream(new FileOutputStream("C:\\inventory\\inventory.dat"));
savefile.writeObject(rpg);
savefile.close();
dirmake = 2 ;
}
catch (Exception e){
String savePath = "c:\\Inventory";
Path invPath = Paths.get(savePath);
try {
Files.createDirectory(invPath);
} catch (IOException ex) {
Logger.getLogger(inventoryGui.class.getName()).log(Level.SEVERE, null, ex);
}
}
}while(dirmake == 1);
}
private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {
titleField.setText("");
iNumberField.setText("");
pCountField.setText("");
priceField.setText("");
stockField.setText("");
restockField.setText("");
inventoryValueField.setText("" );
entireInventoryField.setText("");
}
private void modifyButtonActionPerformed(java.awt.event.ActionEvent evt) {
int mINumber = Integer.parseInt(iNumberField.getText());
double ss = Double.parseDouble(priceField.getText().replaceAll("[^\\d.]", ""));
rpg[mINumber -1] = new rBook(mINumber, titleField.getText(), Integer.parseInt(stockField.getText()), ss, Integer.parseInt(pCountField.getText()));
}
private void addbuttonActionPerformed(java.awt.event.ActionEvent evt) {
double ss = Double.parseDouble(priceField.getText().replaceAll("[^\\d.]", ""));
max ++;
rBook[] rpg2 = Arrays.copyOf(rpg, rpg.length);
rBook[] rpg = Arrays.copyOf(rpg2, max);
rpg[max -1] = new rBook(max, titleField.getText(), Integer.parseInt(stockField.getText()), ss, Integer.parseInt(pCountField.getText()));
System.out.println(max + titleField.getText() + Integer.parseInt(stockField.getText()) + ss + Integer.parseInt(pCountField.getText()));
counter = -1;
System.out.println(max);
for (int x=0; x< max; x++) {
System.out.println("Item Number:" + rpg[5].itemNumber);
System.out.println("Rpg Name:" + rpg[5].itemName);
System.out.println("Copies in stock:" + rpg[5].itemStock);
System.out.println("Price: $" + (rpg[5].itemPrice));
System.out.println("Page Count:" + rpg[5].pCount);
System.out.println("Restocking fee: $" + (rpg[5].rFee));
System.out.println();
System.out.println();
System.out.println(rpg.length);
}
}
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new inventoryGui().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton addbutton;
private javax.swing.JLabel buttonLabel;
private javax.swing.JLabel companyLogo;
private javax.swing.JButton deleteButton;
private javax.swing.JTextField entireInventoryField;
private javax.swing.JLabel entireInventoryLabel;
private javax.swing.JTextField iNumberField;
private javax.swing.JLabel iNumberLabel;
private javax.swing.JTextField inventoryValueField;
private javax.swing.JLabel inventoryValueLabel;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JButton loadButton;
private javax.swing.JButton modifyButton;
private javax.swing.JLabel nameLabel;
private javax.swing.JButton nextButton;
private javax.swing.JTextField pCountField;
private javax.swing.JLabel pCountlabel;
private javax.swing.JButton previousButton;
private javax.swing.JTextField priceField;
private javax.swing.JLabel priceLabel;
private javax.swing.JTextField restockField;
private javax.swing.JLabel restockLabel;
private javax.swing.JButton saveButton;
private javax.swing.JButton searchButton;
private javax.swing.JTextField stockField;
private javax.swing.JLabel stockLabel;
private javax.swing.JTextField titleField;
private javax.swing.JLabel titleLabel;
}
最佳答案
你的问题的一部分是,你正在隐藏你的变量......
max ++;
rBook[] rpg2 = Arrays.copyOf(rpg, rpg.length);
rBook[] rpg = Arrays.copyOf(rpg2, max);
在这里,您已将 rpg
声明为局部变量,因此您对其所做的任何更改都不会被类的其余部分看到。尝试使用更像...的东西
rpg = Arrays.copyOf(rpg2, max);
相反...
您还可以考虑使用System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
相反...但我会先解决你其他问题;)
rBook[] rpg2 = new rBook[rpg.length + 1];
System.arraycopy(rpg, 0, rpg2, 0, rpg.length - 1);
rpg = rpg2;
或者类似的东西......
关于java swing ui 不显示重建的数组索引越界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23729029/
我最近才开始学习 Clojure,所以很抱歉,如果这有点初级: 有人可以向我解释一下两者之间的区别吗: => (def a (lazy-cat [0]
我有一些看起来像这样的数据: X = [[1,2,3,4],[01010],[-1.6]] y = [[4,2]] 我正在尝试使用 tflearn 在这些数据上训练神经网络。我使用的是 TFlearn
我的代码有问题。 我正在尝试从 .txt 文件中提取 channel 名称。我不明白为什么方法 line.split() 给我返回一个长度为 0 的数组: 有人可以帮助我吗? 这是文件.txt: --
def sigmoid(z): # complete the code z = np.asarray(z) if z.ndim == 0: return(1/(1+np.exp(-z))) e
我在访问 3d 数组内的值时遇到问题。有时它给出正确的值,但有时它给出随机的数值。数组内不存在。 import java.util.*; public class Main { public
我有一段代码,执行时会出现此错误。而且我比较新,我似乎无法解决问题。 错误:2011-09-06 12:31:06.094 ForceGauge[266:707] CoreAnimation:忽略异常
我正在尝试限制 http://www.liftdesignphoto.com/test/ 中的滚动因为它让电梯超出了界限。 有没有办法重新计算位置,使其不越界? (也许使用 %)。 谢谢 最佳答案 假
我正在尝试遍历 6 个“国际象棋”棋子的列表。每轮他们移动一个随机数量,如果他们落在另一个上,他们就会“杀死”它。 问题是,当我的 vector 中的最后一 block 杀死另一 block 时,我收
NumberPicker serviceWheel = (NumberPicker) findViewById(R.id.serviceSelector); serviceWheel.setMaxVa
我正在尝试使用 GridLayout 重现此计算器布局 但这就是我用我尝试过的代码得到的结果。 事实上,在设备上情况会变得更糟,它会削减更多必须跨越两行的最后一个相等按钮。
运行测试脚本时出现“标签越界”错误。将注释值与类数进行比较时,confusion_matrix 函数会抛出错误。在我的例子中,注释值是一个图像(560x560)和 number_of_classes
什么是 OOL(越界)代码?我在 ION 编译器中找到了它,但无法理解发生了什么。 bool CodeGeneratorShared::generateOutOfLineCode() { for
这是我正在研究的有趣的事情。 varray.c: static GLint vertices[] = {25, 25, 100, 325,
我的程序将文件读取到字节数组中,然后尝试从该文件中提取 bmp 图像。问题是我遇到了越界错误。 { public static void main( String[] args ) {
我有一个 UITableView,它由从 XML 提要解析的数据数组填充。我正在努力寻找此错误的原因,并想知道是否有人可以帮助我。该错误不会经常发生。它仅在数组数量很大时发生,例如 10-15 个对象
public class GameEntry { private String name; private int score; public GameEntry(String
我遇到了 Storyboard的问题(至少有点惊讶)。 我有一个 ViewController,它包含一个容器 View 以及各种 ImageView 。自然地,选择的 ImageView 决定了容器
我正在尝试为一些 textfield 设置动画。即在屏幕外开始动画并移动到屏幕中央。但就我而言,动画从中心开始并超出 bounds。当我在 viewWillAppear/viewDidAppear 中
closeTs在struct tic给我一个错误 - tsP=0x66 .我尝试从 oracle 条目中填充它,如果没有,我尝试分配一个值。但我在 fillFields 中访问错误.有人可以给我提示
public class Registration { public static void main(String[] args) { final String MY
我是一名优秀的程序员,十分优秀!