Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:34:53+00:00 2026-06-17T17:34:53+00:00

I have download a simple java example from the net.I am trying to compile

  • 0

I have download a simple java example from the net.I am trying to compile the code given below

package ArrayList;
import java.util.ArrayList;

public class SimpleArrayListExample {

    public static void main(String[] args) {

        //create an ArrayList object
        ArrayList<String> arrayList = new ArrayList<String>();

        /*
        Add elements to Arraylist using
        boolean add(Object o) method. It returns true as a general behavior
        of Collection.add method. The specified object is appended at the end
        of the ArrayList.
         */
        arrayList.add("1");
        arrayList.add("2");
        arrayList.add("3");

        /*
        Use get method of Java ArrayList class to display elements of ArrayList.
        Object get(int index) returns and element at the specified index in
        the ArrayList
         */
        System.out.println("Getting elements of ArrayList");
        System.out.println(arrayList.get(0));
        System.out.println(arrayList.get(1));
        System.out.println(arrayList.get(2));
    }
}

I have edited the program as per your suggestion and I can compile and I got the class file.

java SimpleArrayListExample.java

NOw I am trying to execute the file using

java -classpath . ArrayList.SimpleArrayListExample.java

Exception in thread “main” java.lang.NoClassDefFoundError

I google and found out that I have to specify -classpath .

http://www.tech-recipes.com/rx/826/java-exception-in-thread-main-javalangnoclassdeffounderror/ that doesn’t seem to fix the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:34:54+00:00Added an answer on June 17, 2026 at 5:34 pm

    The compiler is warning that the type contained within the collection has not been declared.
    You can use generics to emilinate this warning

    ArrayList<String> arrayList = new ArrayList<String>();
    

    Edit:

    There is a problem with your package structure. The SimpleArrayListExample is not in a directory called ArrayList. To fix

    • Move SimpleArrayListExample.java to a new directory called ArrayList.
    • Compile using:- javac ArrayList/SimpleArrayListExample.java
    • To Run: java ArrayList.SimpleArrayListExample

    Note package names typically use lowercase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code to download a single file . import java.io.FileOutputStream; import java.io.IOException;
I have a simple catalogue app that lets users download product data from an
When I have download sample code from this link and than try to build
I have a simple question Is it possible to download a specific resource file
I have prepared one sample application.When application install in devices download the file from
I have download entire Eclipse Helios/Indigo version Source Code. Now I want to work
I have rich client platform project. To ramble through source code I have download
I need to download all images from a website to which I have username
I have created a Java code for my Android App. String[] MovieName=new String[]{}; for
URL Download http://code.google.com/p/mwiphonesdk/source/browse/#svn/trunk/iMADE/PrepTasks/08 I have code at the location at the link above and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.