Ask Experts Questions for FREE Help !
Ask
    brooksn's Avatar
    brooksn Posts: 2, Reputation: 1
    New Member
     
    #1

    Mar 11, 2003, 12:20 AM
    Java Error: array required, but PRmList found
    Here is my code: I get the error:
    Array required, but PRmList found. Any help would be GREATLY appreciated. Thanks!

    Public class PRm
    {
    Private String PRm;
    Private String movieTitle;
    Private String movieRating;
    Private int seats;

    Public PRm(String prm, String movie, String rating, int sts)
    {
    PRm=prm;
    MovieTitle=movie;
    MovieRating=rating;
    Seats=sts;
    }
    Public String getmovieTitle()
    {
    Return movieTitle;
    }
    }

    Public class PRmList
    {
    PRm[] pRmList;

    Public void createList()
    {
    PRmList = new PRm[5];
    PRmList[0]= new PRm("PR1", "Fast and the Furious", "R", 90);
    PRmList[1]= new PRm("PR2", "Usual Suspects", "R", 70);
    PRmList[2]= new PRm("PR3", "Spy Game", "R", 80);
    PRmList[3]= new PRm("PR4", "Die Hard 3", "R", 60);
    PRmList[4]= new PRm("PR5", "Lord of the Rings", "R", 100);
    }
    }

    Import java.io.*;
    Public class Test
    {
    Public static void main(String[] args)
    {
    PRmList lis = new PRmList();
    Lis.createList();

    Lis[0].getmovieTitle(); // Error is here
    }
    }
    YDG's Avatar
    YDG Posts: 4, Reputation: 1
    New Member
     
    #2

    Mar 17, 2003, 04:07 AM
    Java Error: array required, but PRmList found
    Hi
    The problem is in the way you were referencing the getMovieTitle() method in your main method. The variable "lis" is a PRmlist object, but "getMovieTitle" is not a method of that class, it's a method of the PRm class. Even though the PRmlist object contains an array of PRm objects, you can't access the PRm classes methods directly in this way. If you had made the PRmlist extend the PRm class (called 'inheritance') when you designed the class, then yes it would've worked in the way you were thinking (with a slight modification to what you were doing). What you need to do is access the variable in the PRmlist object you created (pRmList = new PRm[5]), and get the properties of the object (PRm) that the variable is storing. So your code should look like this:

    Public class Test
    {
    Public static void main(String[] args)
    {
    PRmList lis = new PRmList();
    Lis.createList();
    //lis[0].getmovieTitle(); // Error is here

    Lis.pRmList[0].getmovieTitle() //<--- this is the correct way

    //System.out.println(lis.pRmList[0].getmovieTitle()); //<use this to see the result;)
    }
    }

    One other thing you were doing wrong, was trying to treat 'lis' as an array, but in your declaration it was not specified as one (instead of "PRmList lis = new PRmList();", you would need to declare it as "PRmList lis[] = new PRmList();" or "PRmList[] lis = new PRmList();"). I'm guessing you were trying to use an array so you could access the array you created in the PRmlist class, which is on the right track, but an array already exists in the PRmlist class, all you need to do is directly access that array with this:
    Lis.pRmList[x] (where x is a number)
    Lis is an instance of the PRmlist class, you can directly access any of the PRmlist variables and methods.

    Hope that's slightly understandable ;)
    brooksn's Avatar
    brooksn Posts: 2, Reputation: 1
    New Member
     
    #3

    Mar 17, 2003, 04:07 PM
    Java Error: array required, but PRmList found
    Thank you so much, very understandable. :)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Biosinfo.inf file not found, error code 4100 [ 2 Answers ]

Hi, I've got an old extra pc which I'm trying to test a copy of xp on, I've got win xp boot disk(s) and win xp cd. It gets to inspecting computers hardware configuration and then stops and displays the error code. Any suggetions would be great, Thanks

JNLPException[category: Download Error : Exception:java.net.ConnectException: Connect [ 0 Answers ]

Hi all , it's woking in server Because code base = cPanel... if am calling the same application in client/ end User .. Error Connection Refuse.. clear about the Error message: An error occurred while launching/running the application. Title: My Pirate! Vendor: me Category: Download Error

WEbproxy Error message help required [ 3 Answers ]

Hi using windows 98se, suddenly experiencing problems using both IE and outlook express, saying when start up each " msimn and Explorer has performed an illegal function and will shut down." under details it says "... caused an invalid page fault in module <unknown> then loads of codes... I then...

Error Message, System32, COMM.DRV not found [ 1 Answers ]

I'm trying to install software for my dvd cam, but when I do it says. System32 Directory: COMM.DRV file not found Could someone please direct me to where I might be able to download this file as it is not found when I search the PC. Thanks

Java: using an array from the main in a method [ 2 Answers ]

I have the array names in the main of my program and I want to use it in a method FindName.. How would I wright the method header and the call to the method in the main?


View more questions Search