#Ive been getting errors on saving and loading part in my code, need help

1 messages ยท Page 1 of 1 (latest)

gilded oriole
#

Need some help on fixing this

vocal gustBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

Sure, I'd be happy to help you with your Java code. Could you please provide more details about the errors you are encountering and share the relevant code snippets?

hallow path
#

do what the error says?

#

your shoppingmananger interface conains a method SaveList (which should be saveList) which must either be implemented, or your class must be abstract

patent mortar
#

apparently ur WestminsterShoppingManager hasnt implemented SaveList() yet

#

could u share both classes please

#

full code ideally. not just pics

gilded oriole
#

ill send

gilded oriole
#

i keep trying to fix it

#

but i just go in circles

patent mortar
#

can u just share the two classes WestministerShoppingManager and ShoppingManager

#

then its easier to access

#

๐Ÿ™‚

gilded oriole
#

sure

#

just send the code here or

#

send the 2 files

patent mortar
#

u can upload the two files individually

#

our bot will make it nice then

#

๐Ÿ™‚

gilded oriole
#

okay

#

this right?

patent mortar
#

yeah, but dont delete the gist please ๐Ÿ˜„

gilded oriole
#

oh sorry

#

ill resend it

patent mortar
#

without gist, its not visible for mobile users

vocal gustBOT
gilded oriole
#

i thought dismiss meant just removing that msg

patent mortar
#

๐Ÿ‘

#

mh, odd. looks right

#
void SaveList(String Fname, List<Product> products);
// ...
public void SaveList(String Fname, List<Product> products) {
gilded oriole
#

yeah

#

the erorr im getitng is

patent mortar
#

what happens if u click on Implement Methods?

gilded oriole
#

it just creates savelist and loadlist again

hallow path
#

it's not ok

gilded oriole
hallow path
#

you have 2 saveList methods on your interface

#

one with arguments, one without

gilded oriole
#

yeah

hallow path
#

and you only implemented the one with arguments

patent mortar
#

its not on the gist u uploaded though, lol

gilded oriole
#

shit

patent mortar
#

oh nvm, overlooked it

#

yeah. so thats the issue

gilded oriole
patent mortar
#

ur misunderstanding

#

ur interface, the way u wrote it, demands that there are 2 SaveList methods

#

one with args

#

and one without

#

so every class that implements the manager MUST offer both of them

hallow path
#

you have an overloaded method

patent mortar
#

do u only want one? then adjust ur interface

#

see here

#

same with the LoadList

gilded oriole
#

i awnt the one with arguments

patent mortar
#

then remove line 12

#

and line 14

gilded oriole
#

but when i remove the one without arguments

#

the code doesnt run

patent mortar
#

dont do random changes to ur code

#

get rid of what u dont need

#

and then fix the issues that pop up

gilded oriole
patent mortar
#

yeah. the method wants a name and a lis tof products to save

gilded oriole
patent mortar
#

u cant just call it without anything

#

SaveList("foo", someProducts)

#

u have to give it the args

gilded oriole
#

im back to my old problem

hallow path
#

you need to pass in variables

#

Where are the products and fname coming from?

gilded oriole
hallow path
#

no, that is your handling

#

where is the input coming from

patent mortar
#

arguments mean that u expect them from the caller

gilded oriole
#

i havent inputed anything into my main yet

patent mortar
#

u have to pass them when u call it

#

how should SaveList know what to save when u dont give it anything to save

#

it cant guess it

hallow path
#

It expects something like:

String Fname  =  "foo";
List<Product> products = new ArrayList<>();
SaveList(Fname, products);
patent mortar
#

(but with reasonable content)

hallow path
#

kind of, it's just a sample of what will compile

#

Fname, and products should be reasonable content

#

it's just to showcase that when you declare a method that expects something, you do need to pass it in

gilded oriole
#

hmmmm

#

nope

hallow path
#

you declared your method as saying: I want an input of a String and a list of products, but you gave it nothing.

gilded oriole
#

so what i want to do with save is

#

take the stuff in product and write it into a file

#

what ur saying is i didnt give it the product?

hallow path
#

correct

#

you called SaveList without any arguments

gilded oriole
hallow path
#

saveList() <= you passed in nothing

gilded oriole
hallow path
#

and now it doesn't complain

gilded oriole
#

damn

#

okay i understood what just happened lmao

#

same with load im assuming?

#

okay it did save

#

but it saved some weird shit

hallow path
#

load expects your fname

vocal gustBOT
#

MOOC is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.

It consists of two parts, one at beginner, and another at intermediate level. The end of the course is marked by creating your own Asteroids game clone!

Even though the instructions show how to configure and use NetBeans for the course, you can use IntelliJ. To use IntelliJ, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.

Visit MOOC here: https://java-programming.mooc.fi/
(the course is available in both English and Finnish)

About the course - Java Programming

gilded oriole
#

it aint savin

#

@hallow path can u help me out with the saving and loading?

hallow path
#

working on a hobby project, but your class is most likely not Serializable (and a good toString never hurts)

hallow path
#

make your Product Serializable

gilded oriole
gilded oriole
#

is there a different way of doing it instead of making product "serializable"?

hallow path
#
Only objects that support the java.io.Serializable interface can be written to streams. The class of each serializable object is encoded including the class name and signature of the class, the values of the object's fields and arrays, and the closure of any other objects referenced from the initial objects.

The method writeObject is used to write an object to the stream. Any object, including Strings and arrays, is written with writeObject. Multiple objects or primitives can be written to the stream. The objects must be read back from the corresponding ObjectInputstream with the same types and in the same order as they were written.

Primitive data types can also be written to the stream using the appropriate methods from DataOutput. Strings can also be written using the writeUTF method.

The default serialization mechanism for an object writes the class of the object, the class signature, and the values of all non-transient and non-static fields. References to other objects (except in transient or static fields) cause those objects to be written also. Multiple references to a single object are encoded using a reference sharing mechanism so that graphs of objects can be restored to the same shape as when the original was written.

For example to write an object that can be read by the example in ObjectInputStream:
      FileOutputStream fos = new FileOutputStream("t.tmp");
      ObjectOutputStream oos = new ObjectOutputStream(fos);

      oos.writeInt(12345);
      oos.writeObject("Today");
      oos.writeObject(new Date());

      oos.close();
 
Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:
 private void readObject(java.io.ObjectInputStream stream)
     throws IOException, ClassNotFoundException;
 private void writeObject(java.io.ObjectOutputStream stream)
     throws IOException
 private void readObjectNoData()
     throws ObjectStreamException;
gilded oriole