• Post Reply Bookmark Topic Watch Topic
  • New Topic

Amazon web services-running EC2 instance via java program using AWS APIs  RSS feed

 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to java programming and I have been trying to start an aws EC2 instance using a java program that i have written using help from various websites, but I can't seem to succeed after 2 days of trying.

here is my java code


and when i run the program i get this in my console

Exception in thread "main" java.lang.NullPointerException at com.amazonaws.http.HttpClientFactory.createHttpClient(HttpClientFactory.java:92) at com.amazonaws.http.AmazonHttpClient.(AmazonHttpClient.java:200) at com.amazonaws.AmazonWebServiceClient.(AmazonWebServiceClient.java:129) at com.amazonaws.services.ec2.AmazonEC2Client.(AmazonEC2Client.java:196) at com.amazonaws.services.ec2.AmazonEC2Client.(AmazonEC2Client.java:173) at com.amazonaws.services.ec2.AmazonEC2Client.(AmazonEC2Client.java:101) at com.amazonaws.services.ec2.model.StartInstancesRequest.main(StartInstancesRequest.java:25)

Can anyone help me? Am I writing the code right??
 
Rodion Gork
Ranch Hand
Posts: 47
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AmazonEC2Client ec2 = new AmazonEC2Client(credentials);

Am I right supposing that "credentials" here are null - it looks like you never initialize them?
 
Campbell Ritchie
Marshal
Posts: 56209
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have probably not come across the code button yet. Always use it: i edited your post with it and had to break some long lines and doesn't it look better . Please always use copy‑and‑paste for code; you appear to have a compiler error in line 1 and I think you have divided the name of a class in two by mistake. Don't say java.lang.Anything (normally); simply use the class name, and make sure you don't have any classes in your package with the same name as a java.lang class.

Go through books like Effective Java™ by Joshua Bloch and you find warnings against retuning null (page 201). I saw that (line 12) and thought, “He is going to get a Null Exception,”
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the replies. The issue is now resolved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!