• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 47
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the replies. The issue is now resolved.
 
reply
    Bookmark Topic Watch Topic
  • New Topic