The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Why does this Java code generate a NumberFormatException?

SOLVED
Go to solution
Highlighted
Occasional Contributor

Why does this Java code generate a NumberFormatException?

The following Java program:

import com.constantcontact.components.contacts.Contact;
import com.constantcontact.components.generic.response.ResultSet;
import com.constantcontact.exceptions.service.ConstantContactServiceException;
import com.constantcontact.services.contacts.ContactService;

public class Foo
{
	public static void main (String[] args) throws ConstantContactServiceException
	{
		ContactService cs = new ContactService (args [0], args [1]);
		ResultSet c = cs.getContactByEmail (args [2]);
		System.out.println (c.size ());
	}
}

results in a NumberFormatException:

Exception in thread "main" com.constantcontact.exceptions.service.ConstantContactServiceException: java.lang.NumberFormatException: null
	at com.constantcontact.services.contacts.ContactService.getContactByEmail(ContactService.java:172)
	at com.fmb.constantcontact.Foo.main(Foo.java:13)
Caused by: java.lang.NumberFormatException: null
	at java.lang.Integer.parseInt(Integer.java:417)
	at java.lang.Integer.parseInt(Integer.java:499)
	at com.constantcontact.util.Config.loadProperties(Config.java:148)
	at com.constantcontact.util.Config.(Config.java:23)
	at com.constantcontact.util.Config.instance(Config.java:36)
	at com.constantcontact.services.contacts.ContactService.getContactByEmail(ContactService.java:159)
	... 1 more

This doesn't give me the vaguest clue as to what might be wrong with the code.

The API tester gives me the response I expected.

 

Can anyone point me in the right direction?

 

Thanks,

 

Remon

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Honored Contributor

Re: Why does this Java code generate a NumberFormatException?

Hi Remon,

 

The error you're seeing is the code having an issue with loading some of the properties that are defined for the SDK that it needs to function. The specific file that's causing the problem is

src/main/resources/ctct_api.properties

and the specific property is

constantcontact.api.httpcodes.emailcampaignschedulecreated=201

 

The error that you are seeing is stating that the value of that property cannot be parsed as an int, which would lead me to believe that it has been moved, changed, removed, or become corrupted. Are you including the SDK as source files for your project, or are you using a compiled JAR?

 

Sincerely,

Elijah G.
API Support Engineer

View solution in original post

3 REPLIES 3
Highlighted
Honored Contributor

Re: Why does this Java code generate a NumberFormatException?

Hi Remon,

 

The error you're seeing is the code having an issue with loading some of the properties that are defined for the SDK that it needs to function. The specific file that's causing the problem is

src/main/resources/ctct_api.properties

and the specific property is

constantcontact.api.httpcodes.emailcampaignschedulecreated=201

 

The error that you are seeing is stating that the value of that property cannot be parsed as an int, which would lead me to believe that it has been moved, changed, removed, or become corrupted. Are you including the SDK as source files for your project, or are you using a compiled JAR?

 

Sincerely,

Elijah G.
API Support Engineer

View solution in original post

Highlighted
Occasional Contributor

Re: Why does this Java code generate a NumberFormatException?

I downloaded the source fro github but I missed the .properties file. Thanks for setting me on the right track!

 

PS: Where can I download the compiled jarfile from?

 

Highlighted
Honored Contributor

Re: Why does this Java code generate a NumberFormatException?

We've recently gotten the lastest version of our Java SDK up on Maven Central so that you can easily include it in projects as a dependency. You can find info here: https://search.maven.org/#artifactdetails%7Ccom.constantcontact%7Cconstantcontact%7C4.2.0%7Cjar

 

Sincerely,

Elijah G.
API Support Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured