#Ive been getting errors on saving and loading part in my code, need help
1 messages ยท Page 1 of 1 (latest)
<@&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?
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
apparently ur WestminsterShoppingManager hasnt implemented SaveList() yet
could u share both classes please
full code ideally. not just pics
ill send
the full code
i keep trying to fix it
but i just go in circles
can u just share the two classes WestministerShoppingManager and ShoppingManager
then its easier to access
๐
yeah, but dont delete the gist please ๐
without gist, its not visible for mobile users
I uploaded your attachments as Gist.
i thought dismiss meant just removing that msg
๐
mh, odd. looks right
void SaveList(String Fname, List<Product> products);
// ...
public void SaveList(String Fname, List<Product> products) {
what happens if u click on Implement Methods?
it just creates savelist and loadlist again
it's not ok
yeah
and you only implemented the one with arguments
its not on the gist u uploaded though, lol
when i do put arguments theres an erroe
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
you have an overloaded method
i awnt the one with arguments
dont do random changes to ur code
get rid of what u dont need
and then fix the issues that pop up
yeah. the method wants a name and a lis tof products to save
got rid of the unncerssary stuff now
u cant just call it without anything
SaveList("foo", someProducts)
u have to give it the args
arguments mean that u expect them from the caller
i havent inputed anything into my main yet
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
It expects something like:
String Fname = "foo";
List<Product> products = new ArrayList<>();
SaveList(Fname, products);
(but with reasonable content)
this goes into main?
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
i didnt get it
you declared your method as saying: I want an input of a String and a list of products, but you gave it nothing.
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?
inside the case?
saveList() <= you passed in nothing
and now it doesn't complain
damn
okay i understood what just happened lmao
same with load im assuming?
okay it did save
but it saved some weird shit
load expects your fname
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
i get a weird text in my saved file
it aint savin
@hallow path can u help me out with the saving and loading?
working on a hobby project, but your class is most likely not Serializable (and a good toString never hurts)
what do i do then?
make your Product Serializable
ok ill give it a try
instead of the way i did
is there a different way of doing it instead of making product "serializable"?
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;
i cant do something like this?