JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區 » Swing/AWT/SWT/JFace  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 (特急)請問這個Exception是什麼意思,該如何解決
swchen1217





發文: 5
積分: 0
於 2018-08-23 06:35 user profilesend a private message to usersend email to swchen1217reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問以下例外是什麼意思該如何處裡?謝謝
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
  at javax.swing.plaf.basic.BasicTabbedPaneUI.tabForCoordinate(BasicTabbedPaneUI.java:1506)
  at javax.swing.plaf.basic.BasicTabbedPaneUI.setRolloverTab(BasicTabbedPaneUI.java:575)
  at javax.swing.plaf.basic.BasicTabbedPaneUI.access$2100(BasicTabbedPaneUI.java:54)
  at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mouseEntered(BasicTabbedPaneUI.java:3629)
  at java.awt.Component.processMouseEvent(Component.java:6542)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
  at java.awt.Component.processEvent(Component.java:6298)
  at java.awt.Container.processEvent(Container.java:2236)
  at java.awt.Component.dispatchEventImpl(Component.java:4889)
  at java.awt.Container.dispatchEventImpl(Container.java:2294)
  at java.awt.Component.dispatchEvent(Component.java:4711)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
  at java.awt.LightweightDispatcher.retargetMouseEnterExit(Container.java:4676)
  at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4654)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4505)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
  at java.awt.Container.dispatchEventImpl(Container.java:2280)
  at java.awt.Window.dispatchEventImpl(Window.java:2746)
  at java.awt.Component.dispatchEvent(Component.java:4711)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
  at java.awt.EventQueue.access$500(EventQueue.java:97)
  at java.awt.EventQueue$3.run(EventQueue.java:709)
  at java.awt.EventQueue$3.run(EventQueue.java:703)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
  at java.awt.EventQueue$4.run(EventQueue.java:731)
  at java.awt.EventQueue$4.run(EventQueue.java:729)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:swchen1217]
ggininder





發文: 35
積分: 0
於 2018-08-23 07:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
java.lang.ArrayIndexOutOfBoundsException

reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:ggininder]
swchen1217





發文: 5
積分: 0
於 2018-08-23 07:24 user profilesend a private message to usersend email to swchen1217reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ggininder wrote:
java.lang.ArrayIndexOutOfBoundsException

請問要怎麼解決


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:swchen1217]
AJavaLearner





發文: 5
積分: 0
於 2018-08-23 08:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以看原碼嗎?
我好像在eclipse也遇過


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:AJavaLearner]
ggininder





發文: 35
積分: 0
於 2018-08-23 08:02 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
陣列超過索引?
你是在操作頁面時觸發?


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:ggininder]
ggininder





發文: 35
積分: 0
於 2018-08-23 08:09 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
public void add(int index, E element) {
  if (index > size || index < 0)
      throw new IndexOutOfBoundsException(
    "Index: "+index+", Size: "+size);
 
  ensureCapacity(size+1);  // Increments modCount!!
  System.arraycopy(elementData, index, elementData, index + 1,
       size - index);
  elementData[index] = element;
  size++;
    }

這是Arraylist 反組譯 超過索引會自動加大。你可以試試。


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:swchen1217]
ynchang





發文: 151
積分: 0
於 2018-08-23 10:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
建議你先Google查一下有沒有類似的問題

至少提供如下面連結的提問者一樣把自己部份的程式碼也提供出來.
https://stackoverflow.com/questions/2751502/exception-thrown-while-working-with-jtabbedpane


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:ggininder]
swchen1217





發文: 5
積分: 0
於 2018-08-23 10:06 user profilesend a private message to usersend email to swchen1217reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ggininder wrote:
陣列超過索引?
你是在操作頁面時觸發?


觸發btn就會出現
雖然不會影響功能
封裝程jar檔後當然也不會出現
可是就是想把它消掉
用try catch也找不到


swchen1217 edited on 2018-08-23 10:17
reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:swchen1217]
ggininder





發文: 35
積分: 0
於 2018-08-23 10:11 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
swchen1217 wrote:

觸發btn就會出現
雖然不會影響功能
封裝程jar檔後當然也不會出現
可是就是想把它消掉
用try catch也找不到


那就要往回追了,看btn call 哪個method


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:ggininder]
swchen1217





發文: 5
積分: 0
於 2018-08-23 10:13 user profilesend a private message to usersend email to swchen1217reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ggininder wrote:
那就要往回追了,看btn call 哪個method

有一點點複雜我等等放程式碼
ggininder wrote:
1
2
3
4
5
6
7
8
9
10
11
public void add(int index, E element) {
  if (index > size || index < 0)
      throw new IndexOutOfBoundsException(
    "Index: "+index+", Size: "+size);
 
  ensureCapacity(size+1);  // Increments modCount!!
  System.arraycopy(elementData, index, elementData, index + 1,
       size - index);
  elementData[index] = element;
  size++;
    }

這是Arraylist 反組譯 超過索引會自動加大。你可以試試。

什麼意思
有點不太懂


swchen1217 edited on 2018-08-23 10:18
reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:swchen1217]
ggininder





發文: 35
積分: 0
於 2018-08-23 10:43 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
意思是 你遇到超過索引的exception 你要讓他增加size

或者你根本沒用到,你可以覆寫 讓他遇到這個錯誤 不做事情


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:swchen1217]
mmolis





發文: 127
積分: 0
於 2018-08-23 10:59 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
估計是你在使用Collection介面的實例作為你儲存資料使用, 並在操作的時候發生了衝突的事情
1. 陣列長度為 n, 但卻寫了超過 n 的資料進去
2. 在 for loop 或 iterator 該資料的區塊內, 又因故去異動(刪除)該實例的資料
你可以再重新檢視一下你的程式邏輯吧


reply to postreply to post
作者 Re:(特急)請問這個Exception是什麼意思,該如何解決 [Re:ggininder]
swchen1217





發文: 5
積分: 0
於 2018-08-23 11:59 user profilesend a private message to usersend email to swchen1217reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ggininder wrote:
意思是 你遇到超過索引的exception 你要讓他增加size

或者你根本沒用到,你可以覆寫 讓他遇到這個錯誤 不做事情

mmolis wrote:
估計是你在使用Collection介面的實例作為你儲存資料使用, 並在操作的時候發生了衝突的事情
1. 陣列長度為 n, 但卻寫了超過 n 的資料進去
2. 在 for loop 或 iterator 該資料的區塊內, 又因故去異動(刪除)該實例的資料
你可以再重新檢視一下你的程式邏輯吧

以下是我的程式碼
裡面的所有輸出System.out.println();都只是為了要測試的而已

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
void del(int i) {
      try{
        System.out.println("DEL");
        ingredients_add(i);
        qty[i]--;
        System.out.println("qty:"+qty[i]);
        small_total[i]=qty[i]*price[i];
        System.out.println("small_total:"+small_total[i]);
        lb_qty[i].setText(qty[i]+"");
        lb_small_total[i].setText(small_total[i]+"");
        smalltotal-=price[i];
        System.out.println("smalltotal:"+smalltotal);
        tf_ch_small_total.setText(smalltotal+"");
        order_sum--;
        System.out.println("order_sum:"+order_sum);
        tf_info_order_sum.setText(order_sum+"");
        total();
        if(qty[i]==0)
        {
          int k=0;
          for(int x=0;x<40;x++)
            System.out.print(list[x]+",");
          System.out.println();
          for(int n=0;n<40;n++)
          {
            if(list[n]==i){
              list[n]=-1;
              k=n;
              System.out.println("k:"+k);
              break;
            }
            System.out.println("not=-1");
          }
          for(int x=0;x<40;x++)
            System.out.print(list[x]+",");
          System.out.println();
          System.out.println(list[k]);
          System.out.println(list[k+1]);
          System.out.println(order_list_sum);
          order_list_sum--;
          System.out.println(order_list_sum);
          if(order_list_sum!=0 && list[k+1]!=-1)
          {
            for(int e=k;e<order_list_sum+1;e++)
            {
              System.out.println("AA");
              if(list[k+1]!=-1)
              {
                System.out.println("BB");
                tmp=list[e+1];
                list[e]=tmp;
              }
              else
                break;
            }
          }
          //list[order_list_sum]=-1;
          for(int x=0;x<40;x++)
            System.out.print(list[x]+",");
          System.out.println();
          sort();
        }
      }catch(Exception e){}
  }
  void sort()  {
    try{
//    tab_order_list.removeAll();
//    pn_list_1.removeAll();
//    pn_list_2.removeAll();
//    pn_list_3.removeAll();
//    pn_list_4.removeAll();
//    pn_list_5.removeAll();
//    tab_order_list.addTab("1", null, pn_list_1, null);
//    tab_order_list.addTab("2", null, pn_list_2, null);
//    tab_order_list.addTab("3", null, pn_list_3, null);
//    tab_order_list.addTab("4", null, pn_list_4, null);
//    tab_order_list.addTab("5", null, pn_list_5, null);
    //n=0;
    /*for(int i=0;i<order_list_sum;i++)
    {
      if(list[i]!=-1)
        n++;
      else
        break;
    }*/
    for(int a=0;a<53;a++)
    {
      pn_item[a].setVisible(false);
    }
    tab_order_list.updateUI();
    if(order_list_sum!=0)
    {
      item_sum2=0;
      for(int j=0;j<order_list_sum;j++)
      {
        pn_item[list[j]].setVisible(true);
        item_sum2++;
        if(item_sum2<=8)
        {
          pn_item[list[j]].setLocation(0, (item_sum2-1)*70);
          pn_list_1.add(pn_item[list[j]]);
          tab_order_list.setSelectedIndex(0);
        }else if(item_sum2<=16)
        {
          pn_item[list[j]].setLocation(0, (item_sum2-9)*70);
          pn_list_2.add(pn_item[list[j]]);
          tab_order_list.setSelectedIndex(1);
        }else if(item_sum2<=24)
        {
          pn_item[list[j]].setLocation(0, (item_sum2-17)*70);
          pn_list_3.add(pn_item[list[j]]);
          tab_order_list.setSelectedIndex(2);
        }else if(item_sum2<=32)
        {
          pn_item[list[j]].setLocation(0, (item_sum2-25)*70);
          pn_list_4.add(pn_item[list[j]]);
          tab_order_list.setSelectedIndex(3);
        }else if(item_sum2<40)
        {
          pn_item[list[j]].setLocation(0, (item_sum2-33)*70);
          pn_list_5.add(pn_item[list[j]]);
          tab_order_list.setSelectedIndex(4);
        }else if(item_sum2>=40)
        {
          pn_item[list[j]].setLocation(0, (item_sum2-33)*70);
          pn_list_5.add(pn_item[list[j]]);
          tab_order_list.setSelectedIndex(4);
          check_list_full();
        }
      }
      tab_order_list.updateUI();
    }
    }catch(Exception e){}
  }


由btn呼叫del(i)
並傳入要消去的品項編號
若該品項數量消去後等於0就將"list:陣列中位置改為-1
我用-1當作空的這樣好嗎還是要改成別的
用來控制品項順序的陣列"list"如下
1
int list[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};

下面這段意思是把中間有-1(也就是空的)的後面的位置都往前移一個
EX:(數字只是亂打的)
原本2,6.11,5,3,42,9
呼叫del並傳入11 del(11);
2,6,-1,5,3,42,9
2,6,5,5,3,42,9
2,6,5,3,3,42,9
2,6,5,3,42,42,9
2,6,5,3,42,9,9
2,6,5,3,42,9,-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if(order_list_sum!=0 && list[k+1]!=-1)
          {
            for(int e=k;e<order_list_sum+1;e++)
            {
              System.out.println("AA");
              if(list[k+1]!=-1)
              {
                System.out.println("BB");
                tmp=list[e+1];
                list[e]=tmp;
              }
              else
                break;
            }
          }

sort()是用來按"list"陣列的內容放各個品項的panel到TabbedPane的panel裡面
sort執行的順序是先把所有在TabbedPane的panel上面的各個品項的panel remove掉然後再按照list的順序add到上面並setLocation可是我發現removeAll()上面有小品項panel的大panel的時候就會跳例外
所以我就把removeAll()改成先全部setVisible(false)然後在add到上面並setLocation還有setVisible(true)這樣好像就不會跳例外了
可是後來又出現了
這是一個POS系統
上面程式碼裡面的以下部分我有測試過跟這個問題沒有關係
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ingredients_add(i);
        qty[i]--;
        System.out.println("qty:"+qty[i]);
        small_total[i]=qty[i]*price[i];
        System.out.println("small_total:"+small_total[i]);
        lb_qty[i].setText(qty[i]+"");
        lb_small_total[i].setText(small_total[i]+"");
        smalltotal-=price[i];
        System.out.println("smalltotal:"+smalltotal);
        tf_ch_small_total.setText(smalltotal+"");
        order_sum--;
        System.out.println("order_sum:"+order_sum);
        tf_info_order_sum.setText(order_sum+"");
        total();

感覺有點複雜
感謝大家的幫忙
下面附上圖片
https://drive.google.com/open?id=1KlraYeFzGWz2vbQ9-ZQeRWFlNkTw_GGs
https://drive.google.com/open?id=1sM9mh2cXsVthZKSIuEuong_FFLnJqFYK


reply to postreply to post
» JWorld@TW »  Java SE 討論區 » Swing/AWT/SWT/JFace

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8