1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3 out of 5)
Loading ... Loading ...
1,200 views

Applies to:
General java

When
When trying to compile the java file.

Example

JAVA:
  1. public class CompileError {
  2. public static void main(String[] args){
  3. }

Output
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete ClassBody

at CompileError.main(CompileError.java:4)

Your Ad Here
Tags Tags: ,
Categories: Errors when writing software!?, Java
Posted By: HappyFace
Last Edit: 02 May 2009 @ 01 08 PM

EmailPermalinkComments (0)
 22 Apr 2009 @ 1:20 AM 
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4 out of 5)
Loading ... Loading ...
907 views

Applies to:
General java, runtime.

Description:
The error 'java.lang.OutOfMemoryError: Java heap space' is caused when the JVM (Java Virtual Machine) runs out of available memory during processing. This can be caused by:
* a system with less memory than your application / VM requires.

When
Because tmp is always true, the while loop never stops and it continues to add the variable i into the vector until the JVM runs out of memory.

Example

JAVA:
  1. import java.util.Vector;
  2.  
  3. public class OutOfMemory {
  4.  
  5. public static void main(String[] args) {
  6. boolean tmp = true;
  7. int i = 0;
  8. Vector v = new Vector();
  9. while (tmp == true) {
  10. v.add(i);
  11. i++;
  12. }
  13. }
  14. }

Output

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Vector.ensureCapacityHelper(Unknown Source)
at java.util.Vector.add(Unknown Source)
at OutOfMemory.main(OutOfMemory.java:10)

Solution(s)
* add more RAM
* typ: java -Xmx256m in your console window or java -XmxYYYm where YYY is the amount of memory you want to set.
* make sure the condition will ultimately break out of the loop.

Your Ad Here
Tags Tags: ,
Categories: Errors when writing software!?, Java
Posted By: HappyFace
Last Edit: 23 Apr 2009 @ 11 30 PM

EmailPermalinkComments (0)
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
544 views

Applies to:
General java

Description:
Getting the contents of a substring that is shorter than the specified length

When
Length of a string is 16 but when using the substring method to get a string length of 17 an StringIndexOutOfBoundsException will occur.

Example

JAVA:
  1. public class StringExceptionDemo {
  2.  
  3. public static void main(String[] args) {
  4. String tmp = "This is a String";
  5.  
  6. System.out.println("Length of the string: " + tmp.length());
  7. System.out.println(tmp.substring(5,9));     //Good     :: prints out "is a"
  8. System.out.println(tmp.substring(8,17));     //Bad      :: gives: java.lang.StringIndexOutOfBoundsException
  9. }
  10. }

output

Length of the string: 16
is a
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 17
at java.lang.String.substring(Unknown Source)
at StringExceptionDemo.main(StringExceptionDemo.java:10)

Your Ad Here
\/ More Options ...
Change Theme...
  • Users » 888
  • Posts/Pages » 1,444
  • Comments » 506
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Online Users



    No Child Pages.

Forum



    No Child Pages.