The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem:compliles but won't run

3 replies on 1 page. Most recent reply: Oct 16, 2005 8:52 PM by Tapan kumar Rath

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Trevor Hatcher

Posts: 10
Nickname: newbie05
Registered: Oct, 2005

Problem:compliles but won't run Posted: Oct 14, 2005 12:17 PM
Reply to this message Reply
Advertisement
I'm using JDK5 and textpad 4.7.3.
Here is the code, if someone can tell me what is wrong and why it won't run I'd really appreciate it.
P.S. many thanks

import java.util.ArrayList;
import java.util.GregorianCalendar;

public class ArrayListStrings1
{
public static void main(String[] args)
{
GregorianCalendar aDay = new GregorianCalendar();

int year = aDay.get(GregorianCalendar.YEAR);
int month = 1 + aDay.get(GregorianCalendar.MONTH);
int day = aDay.get(GregorianCalendar.DATE);
String dateOne = "\n" + year + "/" + month + "/" + day;
aDay.add(GregorianCalendar.DATE, 14);

year = aDay.get(GregorianCalendar.YEAR);
month = 1 + aDay.get(GregorianCalendar.MONTH);
day = aDay.get(GregorianCalendar.DATE);
String dateTwo = "\n" + year + "/" + month + "/" + day;
aDay.add(GregorianCalendar.DATE, 14);

year = aDay.get(GregorianCalendar.YEAR);
month = 1 + aDay.get(GregorianCalendar.MONTH);
day = aDay.get(GregorianCalendar.DATE);
String dateThree = "\n" + year + "/" + month + "/" + day;
aDay.add(GregorianCalendar.DATE, 14);

year = aDay.get(GregorianCalendar.YEAR);
month = 1 + aDay.get(GregorianCalendar.MONTH);
day = aDay.get(GregorianCalendar.DATE);
String dateFour = "\n" + year + "/" + month + "/" + day;

//Make ArrayList of four dates, imported java.util.ArrayList

ArrayList fourFortnights = new ArrayList();

fourFortnights.add( dateOne );
fourFortnights.add( dateTwo );
fourFortnights.add( dateThree );
fourFortnights.add( dateFour );
}
}


Tapan kumar Rath

Posts: 18
Nickname: papuni
Registered: Sep, 2005

Re: Problem:compliles but won't run Posted: Oct 15, 2005 12:58 AM
Reply to this message Reply
Simply Add the line below as the last line of main method.
System.out.print(fourFortnights);
Then compile and run.

Trevor Hatcher

Posts: 10
Nickname: newbie05
Registered: Oct, 2005

Re: Problem:compliles but won't run Posted: Oct 16, 2005 8:33 PM
Reply to this message Reply
Sorry,
I forgot to include System.out.println(fourFortnights); in my posting, but it is in the code. I am getting a runtime error and I was hoping someone could explain why.

Tapan kumar Rath

Posts: 18
Nickname: papuni
Registered: Sep, 2005

Re: Problem:compliles but won't run Posted: Oct 16, 2005 8:52 PM
Reply to this message Reply
Well It runs perfectly.But if you are getting runtime errors I need to know what errors you are getting.Send a listing of errors.

Flat View: This topic has 3 replies on 1 page
Topic: Save With a given Path Previous Topic   Next Topic Topic: java.lang.OutOfMemoryError

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use