Java全局图像列表InvocationTargetException错误?

时间:2017-03-16 19:55:08

标签: java list javafx

我在尝试拨打Image List时遇到一个相当奇怪的错误,我不确定它为什么会发生。我创建了一个List并且我已添加了项目,但我的程序仍然认为最大索引为零,这意味着它以某种方式为空。谁能帮我解决这个问题?谢谢!

列表:

public class GunImages implements Initializable {
    public static List<Image> gunImages =  new ArrayList<>();
    public static void GunImages(){
            /*
            +=======================================================+
            |                    USP Gun Images                     |
            |                    USP Gun Images                     |
            |                    USP Gun Images                     |
            |                    USP Gun Images                     |
            |                    USP Gun Images                     |
            +=======================================================+
            */
            gunImages.add(new Image("GunImages/USPLead Conduit.png"));//Factory New0
            gunImages.add(new Image("GunImages/USPLead Conduit.png"));//Minimal Wear1
            gunImages.add(new Image("GunImages/USPLead Conduit.png"));//Field Tested2
            gunImages.add(new Image("GunImages/USPLead Conduit.png"));//Well Worn3
            gunImages.add(new Image("GunImages/USPLead Conduit.png"));//Battle Scarred4

            gunImages.add(new Image("GunImages/USPNight Ops.png"));//Factory New5
            gunImages.add(new Image("GunImages/USPNight Ops.png"));//Minimal Wear6
            gunImages.add(new Image("GunImages/USPNight Ops.png"));//Field Tested7
            gunImages.add(new Image("GunImages/USPNight Ops.png"));//Well Worn8
            gunImages.add(new Image("GunImages/USPNight Ops.png"));//Battle Scarred9

            gunImages.add(new Image("GunImages/USPTorque.png"));//Factory New10
            gunImages.add(new Image("GunImages/USPTorque.png"));//Minimal Wear11
            gunImages.add(new Image("GunImages/USPTorque.png"));//Field Tested12
            gunImages.add(new Image("GunImages/USPTorque.png"));//Well Worn13
            gunImages.add(new Image("GunImages/USPTorque.png"));//Battle Scarred14

            gunImages.add(new Image("GunImages/USPGaurdian.png"));//Factory New15
            gunImages.add(new Image("GunImages/USPGaurdian.png"));//Minimal Wear16
            gunImages.add(new Image("GunImages/USPGaurdian.png"));//Field Tested17

            gunImages.add(new Image("GunImages/USPCyrex.png"));//Factory New18
            gunImages.add(new Image("GunImages/USPCyrex.png"));//Minimal Wear19
            gunImages.add(new Image("GunImages/USPCyrex.png"));//Field Tested20
            gunImages.add(new Image("GunImages/USPCyrex.png"));//Well Worn21
            gunImages.add(new Image("GunImages/USPCyrex.png"));//Battle Scarred22

            gunImages.add(new Image("GunImages/USPCaiman.png"));//Factory New23
            gunImages.add(new Image("GunImages/USPCaiman.png"));//Minimal Wear24
            gunImages.add(new Image("GunImages/USPCaiman.png"));//Field Tested25
            gunImages.add(new Image("GunImages/USPCaiman.png"));//Well Worn26

            gunImages.add(new Image("GunImages/USPKill Confirmed.png"));//Factory New27
            gunImages.add(new Image("GunImages/USPKill Confirmed.png"));//Minimal Wear28
            gunImages.add(new Image("GunImages/USPKill Confirmed.png"));//Field Tested29
            gunImages.add(new Image("GunImages/USPKill Confirmed.png"));//Well Worn30
            gunImages.add(new Image("GunImages/USPKill Confirmed.png"));//Battle Scarred31

            /*
            +=======================================================+
            |                    AWP Gun Images                     |
            |                    AWP Gun Images                     |
            |                    AWP Gun Images                     |
            |                    AWP Gun Images                     |
            |                    AWP Gun Images                     |
            +=======================================================+
            */

            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Factory New32
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Minimal Wear33
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Field Tested34
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Well Worn35
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Battle Scarred36

            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Minimal Wear37
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Field Tested38
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Well Worn39
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Battle Scarred40

            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Factory New41
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Minimal Wear42
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Field Tested43
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Well Worn44

            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Factory New45
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Minimal Wear46
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Field Tested47
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Well Worn48

            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Factory New49
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Minimal Wear50
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Field Tested51

            gunImages.add(new Image("GunImages/M4Nitro.png"));//Factory New52
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Minimal Wear53
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Field Tested54
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Well Worn55
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Battle Scarred56

            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Field Tested57
            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Well Worn58
            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Battle Scarred59

            /*
            +=======================================================+
            |                     AK Gun Images                     |
            |                     AK Gun Images                     |
            |                     AK Gun Images                     |
            |                     AK Gun Images                     |
            |                     AK Gun Images                     |
            +=======================================================+
            */

            gunImages.add(new Image("GunImages/AK47Safari Mesh.png"));//Factory New60
            gunImages.add(new Image("GunImages/AK47Safari Mesh.png"));//Minimal Wear61
            gunImages.add(new Image("GunImages/AK47Safari Mesh.png"));//Field Tested62
            gunImages.add(new Image("GunImages/AK47Safari Mesh.png"));//Well Worn63
            gunImages.add(new Image("GunImages/AK47Safari Mesh.png"));//Battle Scarred64

            gunImages.add(new Image("GunImages/AK47Elite Build.png"));//Factory New65
            gunImages.add(new Image("GunImages/AK47Elite Build.png"));//Minimal Wear66
            gunImages.add(new Image("GunImages/AK47Elite Build.png"));//Field Tested67
            gunImages.add(new Image("GunImages/AK47Elite Build.png"));//Well Worn68
            gunImages.add(new Image("GunImages/AK47Elite Build.png"));//Battle Scarred69

            gunImages.add(new Image("GunImages/AK47Emerald Pinstripe.png"));//Factory New70
            gunImages.add(new Image("GunImages/AK47Emerald Pinstripe.png"));//Minimal Wear71
            gunImages.add(new Image("GunImages/AK47Emerald Pinstripe.png"));//Field Tested72
            gunImages.add(new Image("GunImages/AK47Emerald Pinstripe.png"));//Well Worn73
            gunImages.add(new Image("GunImages/AK47Emerald Pinstripe.png"));//Battle Scarred74

            gunImages.add(new Image("GunImages/AK47Blue Laminate.png"));//Factory New75
            gunImages.add(new Image("GunImages/AK47Blue Laminate.png"));//Minimal Wear76
            gunImages.add(new Image("GunImages/AK47Blue Laminate.png"));//Field Tested77
            gunImages.add(new Image("GunImages/AK47Blue Laminate.png"));//Well Worn78

            gunImages.add(new Image("GunImages/AK47Cartel.png"));//Factory New79
            gunImages.add(new Image("GunImages/AK47Cartel.png"));//Minimal Wear80
            gunImages.add(new Image("GunImages/AK47Cartel.png"));//Field Tested81
            gunImages.add(new Image("GunImages/AK47Cartel.png"));//Well Worn82
            gunImages.add(new Image("GunImages/AK47Cartel.png"));//Battle Scarred83

            gunImages.add(new Image("GunImages/AK47Redline.png"));//Minimal Wear84
            gunImages.add(new Image("GunImages/AK47Redline.png"));//Field Tested85
            gunImages.add(new Image("GunImages/AK47Redline.png"));//Well Worn86
            gunImages.add(new Image("GunImages/AK47Redline.png"));//Battle Scarred87

            gunImages.add(new Image("GunImages/AK47Aquamarine Revenge.png"));//Factory New88
            gunImages.add(new Image("GunImages/AK47Aquamarine Revenge.png"));//Minimal Wear89
            gunImages.add(new Image("GunImages/AK47Aquamarine Revenge.png"));//Field Tested90
            gunImages.add(new Image("GunImages/AK47Aquamarine Revenge.png"));//Well Worn91
            gunImages.add(new Image("GunImages/AK47Aquamarine Revenge.png"));//Battle Scarred92

            /*
            +=======================================================+
            |                     M4 Gun Images                     |
            |                     M4 Gun Images                     |
            |                     M4 Gun Images                     |
            |                     M4 Gun Images                     |
            |                     M4 Gun Images                     |
            +=======================================================+
            */

            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Factory New93
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Minimal Wear94
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Field Tested95
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Well Worn96
            gunImages.add(new Image("GunImages/M4VariCamo.png"));//Battle Scarred97

            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Factory New98
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Minimal Wear99
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Field Tested100
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Well Worn101
            gunImages.add(new Image("GunImages/M4Faded Zebra.png"));//Battle Scarred102

            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Factory New103
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Minimal Wear104
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Field Tested105
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Well Worn106
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Battle Scarred107

            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Factory New108
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Minimal Wear109
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Field Tested110
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Well Worn111
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Battle Scarred112

            gunImages.add(new Image("GunImages/M4Nitro.png"));//Factory New113
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Minimal Wear114
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Field Tested115
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Well Worn116
            gunImages.add(new Image("GunImages/M4Nitro.png"));//Battle Scarred117

            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Factory New118
            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Minimal Wear119
            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Field Tested120
            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Well Worn121
            gunImages.add(new Image("GunImages/M4Basilisk.png"));//Minimal Wear122

            gunImages.add(new Image("GunImages/M4Dragon King.png"));//Factory New123
            gunImages.add(new Image("GunImages/M4Dragon King.png"));//Minimal Wear124
            gunImages.add(new Image("GunImages/M4Dragon King.png"));//Field Tested125
            gunImages.add(new Image("GunImages/M4Dragon King.png"));//Well Worn126
            gunImages.add(new Image("GunImages/M4Dragon King.png"));//Battle Scarred127

            gunImages.add(new Image("GunImages/M4Atomic Alloy.png"));//Factory New128
            gunImages.add(new Image("GunImages/M4Atomic Alloy.png"));//Minimal Wear129
            gunImages.add(new Image("GunImages/M4Atomic Alloy.png"));//Field Tested130
            gunImages.add(new Image("GunImages/M4Atomic Alloy.png"));//Well Worn131
            gunImages.add(new Image("GunImages/M4Atomic Alloy.png"));//Battle Scarred132

            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Factory New133
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Minimal Wear134
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Field Tested135
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Well Worn136
            gunImages.add(new Image("GunImages/M4Boreal Forest.png"));//Battle Scarred137

            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Factory New138
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Minimal Wear139
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Field Tested140
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Well Worn141
            gunImages.add(new Image("GunImages/M4Evil Daimyo.png"));//Battle Scarred142
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }
}

调用列表的行:

setAK47Image.setImage(GunImages.gunImages.get(70));

错误:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1456)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
    ...
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1451)
    ... 44 more
Caused by: java.lang.IndexOutOfBoundsException: Index: 70, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at CaseSpinners.AK47CaseSpinController.EmeraldPinstripeAK47(AK47CaseSpinController.java:201)
    at CaseSpinners.AK47CaseSpinController.SpinAK47Case(AK47CaseSpinController.java:82)
    ... 54 more
Exception in thread "JavaFX Application Thread"

1 个答案:

答案 0 :(得分:0)

这个答案相当简单,我从未调用GunImages.GunImages();这个名单从未填满。