質問編集履歴
6
ソースコード変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
at java.lang.reflect.Method.invoke(Method.java:498)
|
48
48
|
|
49
|
-
at versionsmod.versionsmod.init(versionsmod.java:7
|
49
|
+
at versionsmod.versionsmod.init(versionsmod.java:57)
|
50
50
|
|
51
51
|
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
52
52
|
|
@@ -128,7 +128,7 @@
|
|
128
128
|
|
129
129
|
Caused by: java.lang.NoSuchFieldError: ar
|
130
130
|
|
131
|
-
at test.test.init(test.java:1
|
131
|
+
at test.test.init(test.java:21)
|
132
132
|
|
133
133
|
... 44 more
|
134
134
|
|
@@ -146,63 +146,49 @@
|
|
146
146
|
|
147
147
|
```Java
|
148
148
|
|
149
|
-
/*
|
149
|
+
/*38行目*/@EventHandler
|
150
150
|
|
151
151
|
public void init(FMLInitializationEvent e) {
|
152
152
|
|
153
153
|
File modDir = new File(mod_dir);
|
154
154
|
|
155
|
+
System.out.println(Block.class);
|
156
|
+
|
155
157
|
try {
|
156
158
|
|
157
|
-
for(File f : new File(modDir,"cache").listFiles()) {
|
158
|
-
|
159
|
-
if(f.getName().substring(f.getName().lastIndexOf(".")).equals(".zip")) {
|
160
|
-
|
161
|
-
ClassLoader loader = new URLClassLoader(new URL[] {f.toURL()},this.getClass().getClassLoader());
|
162
|
-
|
163
|
-
ZipFile zip = new ZipFile(f);
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
Enumeration<? extends ZipEntry> e1 = zip.entries();
|
168
|
-
|
169
|
-
|
159
|
+
for(String className : loadedClasses) {
|
170
|
-
|
171
|
-
|
160
|
+
|
172
|
-
|
173
|
-
|
161
|
+
if (className.toLowerCase().substring(className.toLowerCase().lastIndexOf(".")).equals(".class")) {
|
174
|
-
|
162
|
+
|
175
|
-
|
163
|
+
System.out.println("load "+className.replace("/", ".").replace(".class", ""));
|
176
|
-
|
164
|
+
|
177
|
-
|
165
|
+
Class clas = getClass().getClassLoader().loadClass(className.replace("/", ".").replace(".class", ""));
|
178
|
-
|
166
|
+
|
179
|
-
|
167
|
+
if(clas.getAnnotation(Mod.class) != null) {
|
180
|
-
|
168
|
+
|
181
|
-
|
169
|
+
Mod m = (Mod) clas.getAnnotation(Mod.class);
|
182
|
-
|
170
|
+
|
183
|
-
|
171
|
+
Object o = clas.newInstance();
|
184
|
-
|
172
|
+
|
185
|
-
|
173
|
+
mods.put(m, o);
|
186
|
-
|
174
|
+
|
187
|
-
|
175
|
+
for(Method meth : clas.getDeclaredMethods()) {
|
188
|
-
|
176
|
+
|
189
|
-
|
177
|
+
Class[] classes = meth.getParameterTypes();
|
190
|
-
|
178
|
+
|
191
|
-
|
179
|
+
if(classes.length==1&&classes[0].getName().equals(FMLInitializationEvent.class.getName())) {
|
192
|
-
|
180
|
+
|
193
|
-
|
181
|
+
try {
|
194
|
-
|
182
|
+
|
195
|
-
|
183
|
+
meth.setAccessible(true);
|
196
|
-
|
184
|
+
|
197
|
-
|
185
|
+
FMLInitializationEvent event = new FMLInitializationEvent();
|
186
|
+
|
198
|
-
|
187
|
+
meth.invoke(o, event);
|
188
|
+
|
199
|
-
|
189
|
+
}catch(InvocationTargetException e11) {
|
200
|
-
|
190
|
+
|
201
|
-
|
191
|
+
e11.printStackTrace();
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
}
|
206
192
|
|
207
193
|
}
|
208
194
|
|
@@ -212,16 +198,10 @@
|
|
212
198
|
|
213
199
|
}
|
214
200
|
|
215
|
-
zip.close();
|
216
|
-
|
217
201
|
}
|
218
202
|
|
219
203
|
}
|
220
204
|
|
221
|
-
System.out.println(mods.size());
|
222
|
-
|
223
|
-
System.out.println(Item.class.getClassLoader()+":"+this.getClass().getClassLoader());
|
224
|
-
|
225
205
|
} catch (Exception e1) {
|
226
206
|
|
227
207
|
e1.printStackTrace();
|
@@ -238,27 +218,11 @@
|
|
238
218
|
|
239
219
|
```Java
|
240
220
|
|
241
|
-
/*1
|
221
|
+
/*19行目*/@EventHandler
|
242
|
-
|
222
|
+
|
243
|
-
public void init(FMLInitializationEvent e)
|
223
|
+
public void init(FMLInitializationEvent e) {
|
244
|
-
|
245
|
-
|
224
|
+
|
246
|
-
|
247
|
-
System.out.println(field.getName());
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
for(Field field : Block.class.getFields()) {
|
252
|
-
|
253
|
-
System.out.println(field.getName());
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
System.out.println(Block.class);
|
258
|
-
|
259
|
-
System.out.println(Block.gravel);
|
260
|
-
|
261
|
-
System.out.println(Item.
|
225
|
+
System.out.println(Item.ar);
|
262
226
|
|
263
227
|
}
|
264
228
|
|
5
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -234,6 +234,38 @@
|
|
234
234
|
|
235
235
|
|
236
236
|
|
237
|
+
test.java(外部Jarの中に入っているtest.class)
|
238
|
+
|
239
|
+
```Java
|
240
|
+
|
241
|
+
/*13行目*/@EventHandler
|
242
|
+
|
243
|
+
public void init(FMLInitializationEvent e) throws Exception {
|
244
|
+
|
245
|
+
for(Field field : Item.class.getFields()) {
|
246
|
+
|
247
|
+
System.out.println(field.getName());
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
for(Field field : Block.class.getFields()) {
|
252
|
+
|
253
|
+
System.out.println(field.getName());
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
System.out.println(Block.class);
|
258
|
+
|
259
|
+
System.out.println(Block.gravel);
|
260
|
+
|
261
|
+
System.out.println(Item.flint);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
|
268
|
+
|
237
269
|
### 試したこと
|
238
270
|
|
239
271
|
|
4
補足情報が別物と勘違いしていたため
test
CHANGED
File without changes
|
test
CHANGED
@@ -134,15 +134,19 @@
|
|
134
134
|
|
135
135
|
```
|
136
136
|
|
137
|
+
test.javaというのは外部Jarの.classのファイルのことです。
|
138
|
+
|
137
139
|
|
138
140
|
|
139
141
|
### 該当のソースコード
|
140
142
|
|
141
143
|
|
142
144
|
|
145
|
+
versionsmod.java
|
146
|
+
|
143
147
|
```Java
|
144
148
|
|
145
|
-
@EventHandler
|
149
|
+
/*71行目*/@EventHandler
|
146
150
|
|
147
151
|
public void init(FMLInitializationEvent e) {
|
148
152
|
|
@@ -254,8 +258,8 @@
|
|
254
258
|
|
255
259
|
### 補足情報
|
256
260
|
|
257
|
-
Minecraft Forge 1.
|
261
|
+
Minecraft Forge 1.7.10-10.13.4.1558
|
258
|
-
|
262
|
+
|
259
|
-
Eclipse 4.
|
263
|
+
Eclipse 4.4
|
260
264
|
|
261
265
|
Windows 10 64bit
|
3
書き方の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
+
### 前提・実現したいこと
|
2
|
+
|
1
3
|
MinecraftというゲームのMODを作っているのですが、そのMODから更に外部のJarファイルを読み込むというものを作っています。
|
2
4
|
|
5
|
+
プログラムが実行されると、外部のJarを読み込み、さらにその中のプログラムをリフレクションを使用し、実行させるというものです。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
arという変数が見つからないという問題が起きています。
|
10
|
+
|
11
|
+
|
12
|
+
|
3
13
|
関係は次のようになっています。
|
4
14
|
|
5
15
|
Minecraft
|
@@ -12,18 +22,222 @@
|
|
12
22
|
|
13
23
|
そこでクラスは見つかるが変数が見つからないというエラーが出る
|
14
24
|
|
15
|
-
|
25
|
+
|
16
|
-
|
26
|
+
|
17
|
-
|
27
|
+
invokeしたプログラムでは変数を書き換えることはありません。
|
28
|
+
|
29
|
+
|
30
|
+
|
18
|
-
|
31
|
+
### 発生している問題・エラーメッセージ
|
32
|
+
|
33
|
+
|
34
|
+
|
19
|
-
|
35
|
+
arという変数が見つからないエラーが出てしまいます。
|
36
|
+
|
20
|
-
|
37
|
+
```
|
38
|
+
|
39
|
+
java.lang.reflect.InvocationTargetException
|
40
|
+
|
41
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
42
|
+
|
43
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
44
|
+
|
45
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
46
|
+
|
47
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
48
|
+
|
49
|
+
at versionsmod.versionsmod.init(versionsmod.java:73)
|
50
|
+
|
51
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
52
|
+
|
53
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
54
|
+
|
55
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
56
|
+
|
57
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
58
|
+
|
59
|
+
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
|
60
|
+
|
61
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
62
|
+
|
63
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
64
|
+
|
65
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
66
|
+
|
67
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
68
|
+
|
69
|
+
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
|
70
|
+
|
71
|
+
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
|
72
|
+
|
73
|
+
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
|
74
|
+
|
75
|
+
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
|
76
|
+
|
77
|
+
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
|
78
|
+
|
79
|
+
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
|
80
|
+
|
81
|
+
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
|
82
|
+
|
83
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
84
|
+
|
85
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
86
|
+
|
87
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
88
|
+
|
89
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
90
|
+
|
91
|
+
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
|
92
|
+
|
93
|
+
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
|
94
|
+
|
95
|
+
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
|
96
|
+
|
97
|
+
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
|
98
|
+
|
99
|
+
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
|
100
|
+
|
101
|
+
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
|
102
|
+
|
103
|
+
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:737)
|
104
|
+
|
105
|
+
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:311)
|
106
|
+
|
107
|
+
at net.minecraft.client.Minecraft.startGame(Minecraft.java:597)
|
108
|
+
|
21
|
-
|
109
|
+
at net.minecraft.client.Minecraft.run(Minecraft.java:942)
|
110
|
+
|
22
|
-
|
111
|
+
at net.minecraft.client.main.Main.main(Main.java:164)
|
112
|
+
|
113
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
114
|
+
|
115
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
116
|
+
|
117
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
118
|
+
|
119
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
120
|
+
|
121
|
+
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
|
122
|
+
|
123
|
+
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
|
124
|
+
|
125
|
+
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
|
126
|
+
|
23
|
-
|
127
|
+
at GradleStart.main(Unknown Source)
|
128
|
+
|
129
|
+
Caused by: java.lang.NoSuchFieldError: ar
|
130
|
+
|
131
|
+
at test.test.init(test.java:17)
|
132
|
+
|
133
|
+
... 44 more
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
### 該当のソースコード
|
140
|
+
|
141
|
+
|
24
142
|
|
25
143
|
```Java
|
26
144
|
|
145
|
+
@EventHandler
|
146
|
+
|
147
|
+
public void init(FMLInitializationEvent e) {
|
148
|
+
|
149
|
+
File modDir = new File(mod_dir);
|
150
|
+
|
151
|
+
try {
|
152
|
+
|
153
|
+
for(File f : new File(modDir,"cache").listFiles()) {
|
154
|
+
|
155
|
+
if(f.getName().substring(f.getName().lastIndexOf(".")).equals(".zip")) {
|
156
|
+
|
157
|
+
ClassLoader loader = new URLClassLoader(new URL[] {f.toURL()},this.getClass().getClassLoader());
|
158
|
+
|
159
|
+
ZipFile zip = new ZipFile(f);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
Enumeration<? extends ZipEntry> e1 = zip.entries();
|
164
|
+
|
165
|
+
while (e1.hasMoreElements()) {
|
166
|
+
|
167
|
+
ZipEntry entry = (ZipEntry) e1.nextElement();
|
168
|
+
|
169
|
+
if (!entry.isDirectory()&&entry.getName().toLowerCase().substring(entry.getName().toLowerCase().lastIndexOf(".")).equals(".class")) {
|
170
|
+
|
171
|
+
System.out.println("load "+entry.getName().replace("/", ".").replace(".class", ""));
|
172
|
+
|
173
|
+
Class clas = Class.forName(entry.getName().replace("/", ".").replace(".class", ""),false,loader);
|
174
|
+
|
175
|
+
if(clas.getAnnotation(Mod.class) != null) {
|
176
|
+
|
177
|
+
Mod m = (Mod) clas.getAnnotation(Mod.class);
|
178
|
+
|
179
|
+
Object o = clas.newInstance();
|
180
|
+
|
181
|
+
mods.put(m, o);
|
182
|
+
|
183
|
+
for(Method meth : clas.getDeclaredMethods()) {
|
184
|
+
|
185
|
+
Class[] classes = meth.getParameterTypes();
|
186
|
+
|
187
|
+
if(classes.length==1) if(classes[0].getName().equals(FMLInitializationEvent.class.getName())) {
|
188
|
+
|
189
|
+
try {
|
190
|
+
|
191
|
+
meth.setAccessible(true);
|
192
|
+
|
193
|
+
meth.invoke(o, new FMLInitializationEvent());//java.lang.reflect.InvocationTargetExceptionエラー
|
194
|
+
|
195
|
+
}catch(InvocationTargetException e11) {
|
196
|
+
|
197
|
+
e11.printStackTrace();
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
zip.close();
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
System.out.println(mods.size());
|
218
|
+
|
219
|
+
System.out.println(Item.class.getClassLoader()+":"+this.getClass().getClassLoader());
|
220
|
+
|
221
|
+
} catch (Exception e1) {
|
222
|
+
|
223
|
+
e1.printStackTrace();
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
```
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
### 試したこと
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
外部Jarの中に以下のソースを書き、実行しました。
|
238
|
+
|
239
|
+
```Java
|
240
|
+
|
27
241
|
for(Field field : Item.class.getFields()) {
|
28
242
|
|
29
243
|
System.out.println(field.getName());
|
@@ -32,196 +246,16 @@
|
|
32
246
|
|
33
247
|
```
|
34
248
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if(f.getName().substring(f.getName().lastIndexOf(".")).equals(".zip")) {
|
50
|
-
|
51
|
-
ClassLoader loader = new URLClassLoader(new URL[] {f.toURL()},this.getClass().getClassLoader());
|
52
|
-
|
53
|
-
ZipFile zip = new ZipFile(f);
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Enumeration<? extends ZipEntry> e1 = zip.entries();
|
58
|
-
|
59
|
-
while (e1.hasMoreElements()) {
|
60
|
-
|
61
|
-
ZipEntry entry = (ZipEntry) e1.nextElement();
|
62
|
-
|
63
|
-
if (!entry.isDirectory()&&entry.getName().toLowerCase().substring(entry.getName().toLowerCase().lastIndexOf(".")).equals(".class")) {
|
64
|
-
|
65
|
-
System.out.println("load "+entry.getName().replace("/", ".").replace(".class", ""));
|
66
|
-
|
67
|
-
Class clas = Class.forName(entry.getName().replace("/", ".").replace(".class", ""),false,loader);
|
68
|
-
|
69
|
-
if(clas.getAnnotation(Mod.class) != null) {
|
70
|
-
|
71
|
-
Mod m = (Mod) clas.getAnnotation(Mod.class);
|
72
|
-
|
73
|
-
Object o = clas.newInstance();
|
74
|
-
|
75
|
-
mods.put(m, o);
|
76
|
-
|
77
|
-
for(Method meth : clas.getDeclaredMethods()) {
|
78
|
-
|
79
|
-
Class[] classes = meth.getParameterTypes();
|
80
|
-
|
81
|
-
if(classes.length==1) if(classes[0].getName().equals(FMLInitializationEvent.class.getName())) {
|
82
|
-
|
83
|
-
try {
|
84
|
-
|
85
|
-
meth.setAccessible(true);
|
86
|
-
|
87
|
-
meth.invoke(o, new FMLInitializationEvent());//java.lang.reflect.InvocationTargetExceptionエラー
|
88
|
-
|
89
|
-
}catch(InvocationTargetException e11) {
|
90
|
-
|
91
|
-
e11.printStackTrace();
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
zip.close();
|
106
|
-
|
107
|
-
}
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
System.out.println(mods.size());
|
112
|
-
|
113
|
-
System.out.println(Item.class.getClassLoader()+":"+this.getClass().getClassLoader());
|
114
|
-
|
115
|
-
} catch (Exception e1) {
|
116
|
-
|
117
|
-
e1.printStackTrace();
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
```
|
124
|
-
|
125
|
-
エラー
|
126
|
-
|
127
|
-
```
|
128
|
-
|
129
|
-
java.lang.reflect.InvocationTargetException
|
130
|
-
|
131
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
132
|
-
|
133
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
134
|
-
|
135
|
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
136
|
-
|
137
|
-
at java.lang.reflect.Method.invoke(Method.java:498)
|
138
|
-
|
139
|
-
at versionsmod.versionsmod.init(versionsmod.java:73)
|
140
|
-
|
141
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
142
|
-
|
143
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
144
|
-
|
145
|
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
146
|
-
|
147
|
-
at java.lang.reflect.Method.invoke(Method.java:498)
|
148
|
-
|
149
|
-
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
|
150
|
-
|
151
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
152
|
-
|
153
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
154
|
-
|
155
|
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
156
|
-
|
157
|
-
at java.lang.reflect.Method.invoke(Method.java:498)
|
158
|
-
|
159
|
-
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
|
160
|
-
|
161
|
-
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
|
162
|
-
|
163
|
-
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
|
164
|
-
|
165
|
-
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
|
166
|
-
|
167
|
-
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
|
168
|
-
|
169
|
-
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
|
170
|
-
|
171
|
-
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
|
172
|
-
|
173
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
174
|
-
|
175
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
176
|
-
|
177
|
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
178
|
-
|
179
|
-
at java.lang.reflect.Method.invoke(Method.java:498)
|
180
|
-
|
181
|
-
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
|
182
|
-
|
183
|
-
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
|
184
|
-
|
185
|
-
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
|
186
|
-
|
187
|
-
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
|
188
|
-
|
189
|
-
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
|
190
|
-
|
191
|
-
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
|
192
|
-
|
193
|
-
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:737)
|
194
|
-
|
195
|
-
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:311)
|
196
|
-
|
197
|
-
at net.minecraft.client.Minecraft.startGame(Minecraft.java:597)
|
198
|
-
|
199
|
-
at net.minecraft.client.Minecraft.run(Minecraft.java:942)
|
200
|
-
|
201
|
-
at net.minecraft.client.main.Main.main(Main.java:164)
|
202
|
-
|
203
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
204
|
-
|
205
|
-
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
206
|
-
|
207
|
-
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
208
|
-
|
209
|
-
at java.lang.reflect.Method.invoke(Method.java:498)
|
210
|
-
|
211
|
-
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
|
212
|
-
|
213
|
-
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
|
214
|
-
|
215
|
-
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
|
216
|
-
|
217
|
-
at GradleStart.main(Unknown Source)
|
218
|
-
|
219
|
-
Caused by: java.lang.NoSuchFieldError: ar
|
220
|
-
|
221
|
-
at test.test.init(test.java:17)
|
222
|
-
|
223
|
-
... 44 more
|
224
|
-
|
225
|
-
```
|
226
|
-
|
227
|
-
invokeしたプログラムでは変数を書き換えることはありません。
|
249
|
+
するとarというフィールドが存在するというのがわかりました。
|
250
|
+
|
251
|
+
しかしinvokeでは見つからないというのがよくわかりません。
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
### 補足情報
|
256
|
+
|
257
|
+
Minecraft Forge 1.6.4-9.11.1.965
|
258
|
+
|
259
|
+
Eclipse 4.3
|
260
|
+
|
261
|
+
Windows 10 64bit
|
2
より詳しい説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
私の作っているMODの関数が呼ばれる
|
10
10
|
|
11
|
-
更にリフレクションを使用して外部のJarを実行
|
11
|
+
更にリフレクションを使用して外部のJarを実行(invoke)
|
12
12
|
|
13
13
|
そこでクラスは見つかるが変数が見つからないというエラーが出る
|
14
14
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
どうしたら変数を見つけることができますか?
|
20
20
|
|
21
|
-
関数はしっかりpublic staticとしています。
|
21
|
+
関数はしっかりpublic staticとしています。(外部からアクセスできるという説明です)
|
22
22
|
|
23
23
|
そして、不思議な事に更に外部のJarを実行したときに以下のようなコード
|
24
24
|
|
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
```
|
34
34
|
|
35
|
-
を実行すると、arが存在することが確認できました。
|
35
|
+
を実行すると、arが存在することが確認できました。しかしinvokeした時に見つからないというのが不思議です。
|
36
36
|
|
37
37
|
```Java
|
38
38
|
|
@@ -223,3 +223,5 @@
|
|
223
223
|
... 44 more
|
224
224
|
|
225
225
|
```
|
226
|
+
|
227
|
+
invokeしたプログラムでは変数を書き換えることはありません。
|
1
エラー文の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,8 +20,22 @@
|
|
20
20
|
|
21
21
|
関数はしっかりpublic staticとしています。
|
22
22
|
|
23
|
+
そして、不思議な事に更に外部のJarを実行したときに以下のようなコード
|
24
|
+
|
23
25
|
```Java
|
24
26
|
|
27
|
+
for(Field field : Item.class.getFields()) {
|
28
|
+
|
29
|
+
System.out.println(field.getName());
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
を実行すると、arが存在することが確認できました。
|
36
|
+
|
37
|
+
```Java
|
38
|
+
|
25
39
|
@EventHandler
|
26
40
|
|
27
41
|
public void init(FMLInitializationEvent e) {
|
@@ -107,3 +121,105 @@
|
|
107
121
|
}
|
108
122
|
|
109
123
|
```
|
124
|
+
|
125
|
+
エラー
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
java.lang.reflect.InvocationTargetException
|
130
|
+
|
131
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
132
|
+
|
133
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
134
|
+
|
135
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
136
|
+
|
137
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
138
|
+
|
139
|
+
at versionsmod.versionsmod.init(versionsmod.java:73)
|
140
|
+
|
141
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
142
|
+
|
143
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
144
|
+
|
145
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
146
|
+
|
147
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
148
|
+
|
149
|
+
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
|
150
|
+
|
151
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
152
|
+
|
153
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
154
|
+
|
155
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
156
|
+
|
157
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
158
|
+
|
159
|
+
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
|
160
|
+
|
161
|
+
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
|
162
|
+
|
163
|
+
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
|
164
|
+
|
165
|
+
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
|
166
|
+
|
167
|
+
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
|
168
|
+
|
169
|
+
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
|
170
|
+
|
171
|
+
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
|
172
|
+
|
173
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
174
|
+
|
175
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
176
|
+
|
177
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
178
|
+
|
179
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
180
|
+
|
181
|
+
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
|
182
|
+
|
183
|
+
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
|
184
|
+
|
185
|
+
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
|
186
|
+
|
187
|
+
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
|
188
|
+
|
189
|
+
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
|
190
|
+
|
191
|
+
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
|
192
|
+
|
193
|
+
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:737)
|
194
|
+
|
195
|
+
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:311)
|
196
|
+
|
197
|
+
at net.minecraft.client.Minecraft.startGame(Minecraft.java:597)
|
198
|
+
|
199
|
+
at net.minecraft.client.Minecraft.run(Minecraft.java:942)
|
200
|
+
|
201
|
+
at net.minecraft.client.main.Main.main(Main.java:164)
|
202
|
+
|
203
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
204
|
+
|
205
|
+
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
|
206
|
+
|
207
|
+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
|
208
|
+
|
209
|
+
at java.lang.reflect.Method.invoke(Method.java:498)
|
210
|
+
|
211
|
+
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
|
212
|
+
|
213
|
+
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
|
214
|
+
|
215
|
+
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
|
216
|
+
|
217
|
+
at GradleStart.main(Unknown Source)
|
218
|
+
|
219
|
+
Caused by: java.lang.NoSuchFieldError: ar
|
220
|
+
|
221
|
+
at test.test.init(test.java:17)
|
222
|
+
|
223
|
+
... 44 more
|
224
|
+
|
225
|
+
```
|