Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Save and load from (Read 14114 times)
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Save and load from
Sep 30th, 2015 at 8:18am
Print Post  
Hi,
I saved the diagram using:
diagram.saveTo(fileName, getApplicationContext());
then I loaded it using:
diagram.loadFrom(o, getApplicationContext());
but if I close my application and then I open it and load it, it gave me this exception:

09-30 10:12:54.048  11896-11896/? W/System.err﹕ java.io.EOFException
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at libcore.io.Streams.readFully(Streams.java:83)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at java.io.DataInputStream.readShort(DataInputStream.java:152)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2064)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at java.io.ObjectInputStream.<init>(ObjectInputStream.java:371)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at com.mindfusion.diagramming.Diagram.b(SourceFile:1750)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1732)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at com.example.silvia.er.MainActivity$4$1.onItemClick(MainActivity.java:222)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.widget.AdapterView.performItemClick(AdapterView.java:334)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.widget.AbsListView$3.run(AbsListView.java:5604)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.os.Looper.loop(Looper.java:145)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:6134)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
09-30 10:12:54.058  11896-11896/? W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

09-30 10:12:54.058  11896-11896/? W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
09-30 10:12:54.078  11896-11896/? E/ViewRootImpl﹕ sendUserActionEvent() mView == null
09-30 10:13:24.088  11896-11896/? V/ActivityThread﹕ updateVisibility : ActivityRecord{3d2f56b1 token=android.os.BinderProxy@f169092 {com.example.silvia.er/com.example.silvia.er.MainActivity}} show : true
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #1 - Sep 30th, 2015 at 4:18pm
Print Post  
Do you mean you are getting that exception only if you restart the application, but it works if you load while same instance still runs? If it shows an exception in ObjectInputStream.readStreamHeader, most likely the file is empty, or you somehow moved the current position to the end of stream if "o" argument in your loadFrom code refers to a stream instead of file name?
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #2 - Oct 2nd, 2015 at 3:15pm
Print Post  
Yes, the problem is when I save, I close the application then when I load the saved file it is empty.
I use this code:
diagram.saveTo(fileName, getApplicationContext());

diagram.loadFrom(o, getApplicationContext());

where o is a string, the name of the file.
This is the exception:
10-02 18:24:52.556  32192-32192/com.example.silvia.er W/System.err﹕ java.io.EOFException
10-02 18:24:52.556  32192-32192/com.example.silvia.er W/System.err﹕ at java.io.DataInputStream.readByte(DataInputStream.java:77)
10-02 18:24:52.556  32192-32192/com.example.silvia.er W/System.err﹕ at java.io.ObjectInputStream.nextTC(ObjectInputStream.java:505)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:752)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.mindfusion.diagramming.Diagram.a(SourceFile:8892)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:8864)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.mindfusion.diagramming.Diagram.b(SourceFile:1751)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.example.silvia.er.MainActivity$4$1.onItemClick(MainActivity.java:230)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.widget.AdapterView.performItemClick(AdapterView.java:334)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.widget.AbsListView$3.run(AbsListView.java:5604)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.os.Looper.loop(Looper.java:145)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:6134)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

10-02 18:24:52.566  32192-32192/com.example.silvia.er W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
10-02 18:24:52.616  32192-32192/com.example.silvia.er E/ViewRootImpl﹕ sendUserActionEvent() mView == null
10-02 18:25:22.606  32192-32192/com.example.silvia.er V/ActivityThread﹕ updateVisibility : ActivityRecord{34dcd60e token=android.os.BinderProxy@3b6d9719 {com.example.silvia.er/com.example.silvia.er.MainActivity}} show : true

How can I solve this problem?
« Last Edit: Oct 2nd, 2015 at 4:36pm by Silvia88 »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #3 - Oct 2nd, 2015 at 5:41pm
Print Post  
I could not reproduce this, please attach a test project that shows the problem.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #4 - Oct 3rd, 2015 at 2:56pm
Print Post  
Here is the code when I load the file, I choose the file to load from an adapter where there are the names of the saved files:
ArrayAdapter<String> arrayadapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, newArray);
                    savedFiles.setAdapter(arrayadapter);
                    savedFiles.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            String o = (String) savedFiles.getItemAtPosition(position);
                            loaded = 1;
                            try {
                                FileInputStream inputStream = openFileInput(o);
                                inputStream.reset();
                                diagram.loadFrom(inputStream);
                                //inputStream.reset();
                                inputStream.close();

                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            saveFile.dismiss();

                        }
                    });
                    saveFile.show();

Here is the code when I save the diagram, it is inside a dialog when I click the positive button:
saveDialog.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            if (nameE.getText().toString().equals("")) {
                                return;
                            }
                            fileName = nameE.getText().toString();
                            File file = activity.getApplicationContext().getFilesDir();
                            String[] arrayFiles = file.list();
                            for (String f : arrayFiles) {
                                Log.d("Load file", "File name: " + f);
                                if (f.compareTo("temp") == 0) {
                                    File deleteFile = new File(f);
                                    deleteFile.delete();
                                }
                            }

                            try {
                                FileOutputStream fileOut = openFileOutput(fileName, Context.MODE_PRIVATE);
                                fileOut.flush();
                                diagram.saveTo(fileOut);
                                fileOut.close();

                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            Log.d("Save file", "Saved File name: " + fileName);

                        }
                    });
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #5 - Oct 5th, 2015 at 10:55am
Print Post  
There's an exception thrown by inputStream.reset() from your code, and it works fine if I comment it out. The reset exception was different than the ones you've copied above anyway, so please attach a test project reproducing them that I could run through debugger in AndroidStudio or Eclipse.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #6 - Oct 8th, 2015 at 4:07pm
Print Post  
Sorry, I tried to reproduce the error but in anther project it works, I don't know way.
May it be done to the fact that I have lots of different shape that I create instead of using the standard ones already defined link Rectangle, Decision ecc?
The error is:
10-08 18:02:05.273 2205-2205/com.example.silvia.er W/System.err﹕ java.io.EOFException
10-08 18:02:05.273 2205-2205/com.example.silvia.er W/System.err﹕ at libcore.io.Streams.readFully(Streams.java:83)
10-08 18:02:05.273 2205-2205/com.example.silvia.er W/System.err﹕ at java.io.DataInputStream.readShort(DataInputStream.java:152)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2064)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at java.io.ObjectInputStream.<init>(ObjectInputStream.java:371)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at com.mindfusion.diagramming.Diagram.b(SourceFile:1750)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at com.example.silvia.er.MainActivity$4$1.onItemClick(MainActivity.java:247)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.widget.AdapterView.performItemClick(AdapterView.java:334)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.widget.AbsListView$3.run(AbsListView.java:5604)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.os.Looper.loop(Looper.java:145)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:6134)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

10-08 18:02:05.283 2205-2205/com.example.silvia.er W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

and is given by:
diagram.loadFrom(inputStream);

now I used the same code I posted above but I comment the reset as you told me.
I have another activity that depends on the diagram loaded or drawn but I reconstruct the element to pass to this activity so I don't think is that the problem
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #7 - Oct 8th, 2015 at 5:06pm
Print Post  
By custom shapes do you mean custom Shape definitions assigned to standard ShapeNode, or are you using custom node types (derived from DiagramNode or ShapeNode)? Does this exception happen only when you load the diagram in second activity?
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #8 - Oct 8th, 2015 at 7:26pm
Print Post  
I use shape like this for example:
float l = -500;  // text bounds left, in %
        float r = 600;
        float t = -500;
        float b = 0;
        new Shape(
                // circle part
                Shape.fromId("Ellipse").getOutline(),

                // no decorations
                null,

                // text region
                new ElementTemplate[]
                        {
                                new LineTemplate(l, t, r, t),
                                new LineTemplate(r, t, r, b),
                                new LineTemplate(r, b, l, b),
                                new LineTemplate(l, b, l, t),
                        },

                Path.FillType.WINDING, "CircleWithTextAbove");

No, it happens even if I don't go in the second activity
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #9 - Oct 9th, 2015 at 8:03am
Print Post  
Both standard shapes and yours are saved only by their string identifier, so this shouldn't lead to exception.

The last stack trace shows the input is an empty stream again, e.g. you can read the top few lines as ObjectInputStream constructor (<init> method) being unable to read enough bytes even for a 'short' value when it tries to read header.

Check the debugger log window to see if there isn't some exception thrown when saving the file, also examine your code to see if it isn't creating empty files with same names as diagram ones at some point.

Perhaps add a test button that just calls Diagram's saveTo, clearAll and loadFrom methods and click it to verify if problem is in our serialization code. If it doesn't throw exceptions then, you should look for the problem in your own code, such as overwriting the files with data in other format.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #10 - Oct 9th, 2015 at 10:03am
Print Post  
I understood where is the problem, it is due to saveInstanceState, so I could reproduce a project that gives this error, where can I load the project to you?

Here is the error:
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ java.io.EOFException
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at libcore.io.Streams.readFully(Streams.java:83)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at java.io.DataInputStream.readShort(DataInputStream.java:152)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2064)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at java.io.ObjectInputStream.<init>(ObjectInputStream.java:371)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at com.mindfusion.diagramming.Diagram.b(SourceFile:1750)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at com.mindfusion.diagramming.Diagram.loadFrom(SourceFile:1744)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at com.example.silvia.example.MainActivity$1$1.onItemClick(MainActivity.java:104)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.widget.AdapterView.performItemClick(AdapterView.java:334)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.widget.AbsListView.performItemClick(AbsListView.java:1536)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.widget.AbsListView$PerformClick.run(AbsListView.java:3683)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.widget.AbsListView$3.run(AbsListView.java:5604)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.os.Looper.loop(Looper.java:145)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:6134)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)

10-09 11:53:26.854 29373-29373/com.example.silvia.example W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #11 - Oct 9th, 2015 at 10:09am
Print Post  
Use the Attachment field shown under text area for forum posts.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #12 - Oct 9th, 2015 at 10:22am
Print Post  
I tried but it gave me an error that I can't attach that file
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Save and load from
Reply #13 - Oct 9th, 2015 at 11:41am
Print Post  
It should be clear enough from the error message how to attach the file. If the forum software doesn't like archive's extension, use a zip archive. If it's too large, remove some files from the zip, e.g. there's no need to include the diagram's and android-support jar files.
  
Back to top
 
IP Logged
 
Silvia88
Full Member
***
Offline


I Love MindFusion!

Posts: 121
Joined: Aug 31st, 2015
Re: Save and load from
Reply #14 - Oct 9th, 2015 at 12:02pm
Print Post  
ok, here it is, I load only the mainActivity and the two layouts
  

example2__2_.zip ( 25 KB | 172 Downloads )
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint