在java中,int无法解除引用错误

时间:2017-07-16 02:31:26

标签: java

我试图将一个字符串拆分为3个整数,但我得到了错误" int无法解除引用"关于Dr java请帮忙

代码:

public class ValidDate

{
  public int validYear;
  public int validMonth;
  public int validDay;

  public ValidDate(String validDate )throws Exception
  {
  validYear = Integer.parseInt(validDate).split[1];
 validMonth = Integer.parseInt(validDate).split[2];
    validDay = Integer.parseInt(validDate).split[3];
.....}

2 个答案:

答案 0 :(得分:0)

首先拆分字符串,然后将它们解析为int。像这样:

!SESSION 2017-07-16 08:09:16.099 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_65
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments:  -keyring /Users/smreehaan/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -data @noDefault -keyring /Users/smreehaan/.eclipse_keyring -showlocation

!ENTRY org.eclipse.osgi 4 0 2017-07-16 08:09:16.700
!MESSAGE Bundle reference:file:org.apache.ant_1.8.3.v201301120609/@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-07-16 08:09:16.704
!MESSAGE Bundle reference:file:org.apache.jasper.glassfish_2.2.2.v201205150955.jar@4 not found.

答案 1 :(得分:0)

When looking at the documentation for Integer我们看到它可以提供给parseInt()的字符串类型非常具体。

此外,您似乎正在尝试访问从您认为是数组的int Integer.parseInt(validDate)返回的split上的某个变量。但是,您无法执行此操作,因为int是基本类型。这是您看到的错误的来源。