小编use*_*609的帖子

删除*char []

如果我尝试删除一个字符,我会收到访问冲突错误.

继承我的代码:

int main()
{
    char *myString = new char[32];
    myString = "Hello";
    cout << myString;
    cin.get();

    delete [] myString;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我也试过了

delete myString
Run Code Online (Sandbox Code Playgroud)

但我仍然得到访问违规错误

c++

2
推荐指数
1
解决办法
520
查看次数

Java gridbaglayout问题

我在调整我的组合框时遇到问题,因此它更接近'band directory'标签.如何将组合框向左移动,除标签外仅5px.我已经尝试为我的标签设置水平插图,为我的组合框设置负插图,但仍然无效.

这是我的代码:

public void createGUI()
{
   main_panel = new JPanel();
   main_panel.setLayout(new GridBagLayout());
   GridBagConstraints gc = new GridBagConstraints();

   label = new JLabel("Band Directory:");
   band_combobox = new JComboBox();
   members_panel = new JPanel();
   members_panel.setBorder(title);
   members_list = new JLabel();
      members_panel.add(members_list);

   gc.fill = GridBagConstraints.HORIZONTAL;
   gc.gridx = 0;
   gc.gridy = 0;
   gc.insets = new Insets(0, 0, 10, 0);
      main_panel.add(label, gc);

   gc.fill = GridBagConstraints.HORIZONTAL;
   gc.gridx = 1;
   gc.gridy = 0;
   gc.insets = new Insets(0, 0, 10, 0);
      main_panel.add(band_combobox, gc);

   gc.fill = GridBagConstraints.HORIZONTAL;
   gc.gridx = 0;
   gc.gridy …
Run Code Online (Sandbox Code Playgroud)

java swing jpanel gridbaglayout

2
推荐指数
1
解决办法
190
查看次数

类Java中的Arraylists

我试图将CD对象添加到CD的ArrayList的Band Object的ArrayList成员字段中.band_index是Band ArrayList的索引,当它从组合框中选择时,我已经检查了band_index确实分配了所选波段的正确索引.band.get(band_index).addCD(cd);当我去调用当前Band的addCD方法时,我在这行代码上得到一个Null Pointer Exception .

主要课程:

public void addCD() {
    CD cd = new CD(t, y);

    band.get(band_index).addCD(cd); //NULL pointer Exception on this line
            updateCDs();
}

//Method to print out all the CDs of a band
public void updateCDs() {
    String list = "";
    for(int i = 0; i < band.size(); i++)
    {
          //band_index is the index of the selected band in the combobox    
          if(i == band_index) {
            for(int j = 0; j < band.get(i).getCDs().size(); j++) {
                list …
Run Code Online (Sandbox Code Playgroud)

java arrays oop arraylist

0
推荐指数
1
解决办法
283
查看次数

标签 统计

java ×2

arraylist ×1

arrays ×1

c++ ×1

gridbaglayout ×1

jpanel ×1

oop ×1

swing ×1