There is an ATM GUI.class interface.
In the ATM class, if the user clicks, he will use Java reflection to dynamically call my Card.class.
The ATM class has this variable:
int userBalanceField = 100;
I am trying to dynamically change it to Integer.MAX_VALUE.
Here is the scroll function in an ATM:
Object object;
Class class_ = null;
ClassLoader classLoader;
this.printToScreen("Loading Card");
String string = "." + File.separator + "Card.class";
File file = new File(string);
ClassLoader classLoader2 = classLoader = ClassLoader.getSystemClassLoader();
try {
object = new URL("file:" + System.getProperty("user.dir") + File.separator + "Card.class");
class_ = Card.class;
}
catch (MalformedURLException var6_7) {
var6_7.printStackTrace();
}
object = "Card";
this.printToScreen("Reading card data and verifying ATM");
try {
Method method = class_.getMethod("swipe", ATM.class);
Data data = (Data)method.invoke(null, this);
if (data == null) {
this.printToScreen("Machine considered invalid");
} else {
this.user = data;
this.tempEntry = "";
this.screenState = 2;
this.updateScreen();
}
}
catch (SecurityException var8_11) {
this.printToScreen("Security Exception when swiping card.");
}
catch (NoSuchMethodException var8_12) {
this.printToScreen("No Such method exception when swiping card.");
}
catch (IllegalArgumentException var8_13) {
this.printToScreen("Illegal Argument exception when swiping card.");
}
catch (IllegalAccessException var8_14) {
this.printToScreen("Illegal Access exception when swiping card.");
}
catch (InvocationTargetException var8_15) {
this.printToScreen("Invocation Target exception when swiping card.");
}
Here is my attempt.
public static ATM.Data swipe(ATM anATM){
Class atmClass = anATM.getClass();
try {
Field moneyInMachineField = atmClass.getDeclaredField("moneyInMachine");
System.out.println("Loading field..." + moneyInMachineField.getName());
Field userBalanceField = atmClass.getDeclaredField("userBalance");
userBalanceField.setAccessible(true);
ATM.Data result = new ATM.Data(cardNumber, accountNumber, name, pinNumber);
userBalanceField.set(result, Integer.MAX_VALUE);
return result;
} catch (IllegalAccessException
| NoSuchFieldException
| SecurityException e) {
e.printStackTrace();
}
return null;
}
I keep getting Invocation Target exception while scrolling the map.
user6270045
source
share