Java System.NullPointerException:尝试反引用null对象
请帮我写代码,我是Java/SF新手,我不理解整个代码 下面的代码应返回18岁以下、18至30岁及以上人群的三个值 我想学习的编码和我的意见,所有的行,如果有什么错误,请纠正我 在我得到错误的那一刻: System.NullPointerException:尝试反引用null对象 Class.testfor1_c.getEZRen:第18行第1列 类。testfor1_c.:第4行第1列Java System.NullPointerException:尝试反引用null对象,java,class,controller,salesforce,apex,Java,Class,Controller,Salesforce,Apex,请帮我写代码,我是Java/SF新手,我不理解整个代码 下面的代码应返回18岁以下、18至30岁及以上人群的三个值 我想学习的编码和我的意见,所有的行,如果有什么错误,请纠正我 在我得到错误的那一刻: System.NullPointerException:尝试反引用null对象 Class.testfor1_c.getEZRen:第18行第1列 类。testfor1_c.:第4行第1列 public class testfor1_c { public testfor1_c(ApexPages
public class testfor1_c {
public testfor1_c(ApexPages.StandardController stdcontroller) {
getEZRen();
}
public Integer Count_u18 {get; set;} // variable for people < 18
public Integer Count_1830 {get; set;} // variable for people >=18 AND <30
public Integer Count_g30 {get; set;} // variable for people >30
public void getEZRen() {
List<Einzelrisiko__c> EZRList = [SELECT Alter__c FROM Einzelrisiko__c]; // create List EZRList with the information Alter__c of all people
FOR (Einzelrisiko__c EZR : EZRList) { // Loop thru the all people
IF(EZR.Alter__c < 18) { Count_u18++; } // if Alter__c < 18 variable Count_u18 increase
IF(EZR.Alter__c >= 18 && EZR.Alter__c <=30) { Count_1830++; } // if Alter__c >=18 AND <=30 variable Count_1830 increase
IF(EZR.Alter__c > 30) { Count_g30++; } // if Alter__c > 30 variable Count_g30 increase
}
}
}
<apex:page standardcontroller="account" extensions="testfor1_c">
Anzahl {!Count_u18} // show the value of people <18
Anzahl {!Count_1830} // show the value of people >=18 AND <=30
Anzahl {!Count_g30} // show the value of people >30
</apex:page>
提前感谢,,
peXIFEZR.Alter\uuu c>=18&&EZR.Alter\uu c您只需要初始化整数属性
希望它能帮助你好的,你说支票是什么意思?我是Java和Salesforce的新手。这意味着EZR.Alter__;c在某个时候为null,你必须检查它是否为null。就像你可以使用ifEZR.Alter_u_;c=null用于在出现null值时执行操作----通过此链接,在调试模式下运行代码一次。我仍然得到错误,请查看下面我的帖子。
public class testfor1_c {
public testfor1_c(ApexPages.StandardController stdcontroller) {
Count_u18 = 0;
Count_1830 = 0;
Count_g30 = 0;
getEZRen();
}
public Integer Count_u18 {get; set;} // variable for people < 18
public Integer Count_1830 {get; set;} // variable for people >=18 AND <30
public Integer Count_g30 {get; set;} // variable for people >30
public void getEZRen() {
List<Einzelrisiko__c> EZRList = [SELECT Alter__c FROM Einzelrisiko__c]; // create List EZRList with the information Alter__c of all people
for(Einzelrisiko__c EZR : EZRList) { // Loop thru the all people
IF(EZR.Alter__c < 18) { Count_u18++; } // if Alter__c < 18 variable Count_u18 increase
IF(EZR.Alter__c >= 18 && EZR.Alter__c <=30) { Count_1830++; } // if Alter__c >=18 AND <=30 variable Count_1830 increase
IF(EZR.Alter__c > 30) { Count_g30++; } // if Alter__c > 30 variable Count_g30 increase
}
}
}