Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: java package problem

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java package problem

    //india.java
    package mtv;
    class india{
    public void file(){
    System.out.println("hellooo");
    }
    -------------------------------------------------------
    //chair.java
    package web;
    import mtv.*;
    class chair
    {
    public static void main(String a[])
    {
    chair c= new chair();
    c.file();
    }
    }

    on compiling chair.java errors are coming like package mtv doesnot exist


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: java package problem

    package mtv doesnot exist
    Where is the package mtv located when you compile the program? Can the javac program find it?
    Is its definition on the classpath?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: java package problem

    Package "mtv" contains a single class, "india". (BTW, please use Initial capitals for classnames.)

    In package "web" you declare a single class "chair", and import "mtv". But you never use a _class_ definition from mtv. Rather, you instantiate an object of the type you haven't finished defining yet, and then invoke file(), which does not exist (in class "chair").

    There are a number of problems here, and you need to solve them to even get to the point where the import of mtv makes sense.

    - You need to consider the access modifiers for india class so other classes can see it.
    - You need to fix your main() method so it actually uses the india class to get access to file() [if this is your intention; this is unclear]

    Taking the time to learn and leverage an IDE like Eclipse or NetBeans will show you all the places your current code is syntactically and structurally incorrect.
    Last edited by jdv; August 29th, 2014 at 09:06 AM.

Similar Threads

  1. how to import/ access classes created in one package in another package
    By ydandurkar in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 11th, 2014, 11:12 AM
  2. Replies: 1
    Last Post: August 5th, 2012, 05:01 AM
  3. Problem with Excelapi: Error: package jxl does not exist
    By Rob Aiello in forum What's Wrong With My Code?
    Replies: 13
    Last Post: February 21st, 2012, 09:52 PM
  4. Simple package problem, package does not exist error
    By Farmer in forum Object Oriented Programming
    Replies: 3
    Last Post: August 23rd, 2011, 11:18 AM
  5. package config problem?
    By droidtech1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 29th, 2011, 11:01 AM