-5

I am getting above error in following code

public List<phonesterDat> getCompanyData() {
  List<phonesterDat> var1 = new List<phonesterDat>();
  List<Account> accounts = [select DD_Segment__c from Account];
  List<Keyword__c> keywords = [select kw__c from Keyword__c];

  for (Keyword__c keyword : keywords) {
    phonesterDat var = new phonesterDat();
    String str = keyword.kw__c;
    var.setType(str);
    Integer cnt = 0;
    for (Account acc : accounts) {
      if (acc.DD_Segment__c.contains(str)) {
        cnt = cnt+1;
      }
    }
    var.setTotal(cnt);
    var1.add(var);
  }

  return var1;
}
  • 2
    Is there a line number where it throws the error? – Rao Nov 20 '12 at 7:43
  • 3
    @Bhushan Can you phrase this as a question please, and show what you've tried so far? – Matt Lacey Nov 20 '12 at 7:44
  • 2
    I think it maybe acc.DD_Segment__c, which is null and therefore .contains is blowing up. That said, it should tell you the line number in the exception stack trace. – techtrekker Nov 20 '12 at 8:09
  • acc.DD_Segment__c was the problem. Thanks! – Bhushan Lodha Nov 20 '12 at 9:09
  • @BhushanLodha Can you mark the appropriate answer as accepted? You'll find over time that if you don't do so people will be less inclined to help you out. Also, if you could rephrase the question as requested above that would be appreciated! – Matt Lacey Nov 21 '12 at 3:04
2

Looking at the code given, chances are you're getting a Keyword__c result from your query which has a null value in the field kw__c, and as such you'd get this error around here:

String str = keyword.kw__c;
var.setType(str);

That said, I can't be sure and really you need to let us know have you've tried, and you've not listed the definition of phonesterDat so the error could easily be in the setType() method and we'd be none the wiser.

I recommend using the debug tools available (even just logs) to see what's null and where.

|improve this answer|||||
1

(Converting comment to answer)

I think it maybe acc.DD_Segment__c, which is null and therefore .contains is blowing up.

Add a not null check before doing the .contains(). (Or alternatively Where DD_Segment__c!=NULL to the soql query)

That said, it should tell you the line number in the exception stack trace.

|improve this answer|||||
0

You could try and solve this by debugging. Enable Debug Logs for your user under Admin Setup -> Monitoring. You can use System.debug() in your apex code for output to the debug logs.

I support LaceySnr in his answer, you probably have a null value in the kw__c field of keyword.

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.