您好我是Java新手,我在运行Apple提供的*command = '\0';
文件时遇到问题。 (我试图以编程方式从iTunes Connect下载销售报告)
我首先反编译了Autoingestion.class
文件并将其保存为.class
。然后我创建了一个新文件夹并将.java
和.class
文件导入其中。但是,我在运行该文件时遇到此错误,并且我不了解如何解决该错误。我以为我已经在脚本中声明了变量.java
。有谁解释一下? :)
这是错误:
localObject2

这是Java代码:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
localObject2 cannot be resolved to a variable
localObject2 cannot be resolved to a variable
localObject2 cannot be resolved to a variable
localObject1 cannot be resolved to a variable
localObject2 cannot be resolved to a variable
localObject1 cannot be resolved to a variable
localObject2 cannot be resolved to a variable
localObject1 cannot be resolved to a variable
at Autoingestion.main(Autoingestion.java:33)

答案 0 :(得分:1)
Object localObject1 = null;
Object localObject2 = null;
主方法中间的这两行应位于主方法的顶部。
答案:
public static void main(String[] paramArrayOfString) {
int i = 0;
String str1 = null;
// ...
String str6 = null;
Object localObject1 = null;
Object localObject2 = null;
Java要求在代码中引用变量之前声明变量。这与Java一样,与大多数编译语言一致,但在其他脚本语言中,如 JavaScript ,由于variable hoisting,此代码将在没有变量错误的情况下运行。
我以为我已经在脚本中声明了变量localObject2。
你做到了。就在他们第一次使用之前。在声明变量之前,有四种用法。
localObject2 = str7 + "/" + str6; // Error 1
...
File localFile2 = new File((String)localObject2); // Error 2
...
localObject1 = Calendar.getInstance(); // Error 4
localObject2 = new SimpleDateFormat("yyyyMMdd"); // Error 5
// there's 5 other uses that occurred before it was initialized