IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Impossible de sérialiser => Pas de constructeur sans paramètres


Sujet :

VB.NET

  1. #1
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 5
    Points : 2
    Points
    2
    Par défaut Impossible de sérialiser => Pas de constructeur sans paramètres
    Bonjour bonsoir,


    Depuis quelques heures maintenant je reste coincé à un endroit où je patine dans VB 10 EXPRESS; il me met ce message d'erreur ci : http://puu.sh/6xPW1.JPG.


    Voici le code de la page principale :



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    Imports System.Xml.Serialization
    Imports System.IO
     
    Public Class Accueil
     
        Private _FenetreAjout As AjoutFIche
        Private _FilmEnVisualisation As Film
        Private _ListeFilms As List(Of Film)
        Public Property ListeFilms As List(Of Film)
            Get
                Return _ListeFilms
            End Get
            Set(ByVal value As List(Of Film))
                _ListeFilms = value
            End Set
        End Property
     
        Private Sub ListeFilms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            RichTextBox2.Enabled = False
            LBL_NB_FILMS.Text = listbox_films.Items.Count
            'Instancie une nouvelle liste
            _ListeFilms = New List(Of Film)
     
            'Récupère les infos
            Deserialisation()
     
            'MAJ la liste de films
            UpdateListe()
     
        End Sub
     
        Private Sub ListeFilms_FormClosing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
            'Sérialise les films lors de la fermeture
            Serialisation()
        End Sub
     
        Private Sub listbox_films_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox_films.SelectedIndexChanged
     
            'On vérifie qu'on a sélectionné quelque chose
            If Not listbox_films.SelectedItem Is Nothing Then
                'Retrouve le film avec ce nom
                For Each FilmALister As Film In _ListeFilms
                    If FilmALister.Nom = listbox_films.SelectedItem.ToString Then
                        'L'insère dans une variable globale
                        Me._FilmEnVisualisation = FilmALister
                    End If
                Next
     
                'On MAJ les infos de la fiche
                Me.LBL_TITRE.Text = Me._FilmEnVisualisation.Nom
                Me.RichTextBox2.Text = Me._FilmEnVisualisation.Synopsis
                Me.LBL_NOTE.Text = Me._FilmEnVisualisation.NotePerso & " / 20"
                Me.LBL_DUREE.Text = Me._FilmEnVisualisation.Duree
                Me.LBL_TYPE.Text = Me._FilmEnVisualisation.Type
                Me.LBL_STATUE.Text = Me._FilmEnVisualisation.Statue
                Me.IMG_FILM.ImageLocation = Me._FilmEnVisualisation.IMGURL
            End If
     
        End Sub
     
        Public Sub UpdateListe()
            'On vide la liste et on la reremplit
            listbox_films.Items.Clear()
            'Parcourt les films de la bibliothèque
            For Each FilmALister As Film In _ListeFilms
                'Remplit la liste en se basant sur le nom (vu que j'ai surchargé ToString)
                'A le même effet que FilmALister.Nom sans la surcharge.
                listbox_films.Items.Add(FilmALister)
            Next
            LBL_NB_FILMS.Text = listbox_films.Items.Count
        End Sub
     
    #Region "Boutons modif fiche"
     
        Private Sub BT_DELETE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_DELETE.Click
     
            'Confirmation
            If MsgBox("Etes vous certain de vouloir supprimer ce film ?", vbYesNo, "Confirmation") Then
                'On le retire de la liste
                Me._ListeFilms.Remove(_FilmEnVisualisation)
            End If
     
            'MAJ
            UpdateListe()
            LBL_DUREE.Text = ""
            LBL_NOTE.Text = ""
            LBL_STATUE.Text = ""
            LBL_TITRE.Text = "Titre"
            LBL_TYPE.Text = ""
            RichTextBox2.Text = ""
            IMG_FILM.ImageLocation = ""
        End Sub
     
        Private Sub BT_NEW_FICHE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_NEW_FICHE.Click
            'Si nouveau film, on passe nothing
            _FenetreAjout = New AjoutFIche(Nothing)
            _FenetreAjout.Show()
        End Sub
     
        Private Sub BT_MAJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_MAJ.Click
            'Si une MAJ, on passe le paramètre du film actuel
            _FenetreAjout = New AjoutFIche(_FilmEnVisualisation)
            _FenetreAjout.Show()
        End Sub
     
    #End Region
     
    #Region "Sauvegarde et récupération"
     
        Private Sub Deserialisation()
            If File.Exists("BibliothequeFilm.xml") Then
                'On ouvre le fichier et récupère son flux
                Dim FluxDeFichier As Stream = File.OpenRead("BibliothequeFilm.xml")
                Dim Deserialiseur As New XmlSerializer(GetType(List(Of Film)))
                'Désérialisation et conversion de ce qu'on récupère dans le type « Film »
                _ListeFilms = Deserialiseur.Deserialize(FluxDeFichier)
                'Fermeture du flux
                FluxDeFichier.Close()
            End If
        End Sub
     
        Private Sub Serialisation()
            'On crée le fichier et récupère son flux
            Dim FluxDeFichier As FileStream = File.Create("BibliothequeFilm.xml")
            Dim Serialiseur As New XmlSerializer(GetType(List(Of Film)))
            'Sérialisation et écriture
            Serialiseur.Serialize(FluxDeFichier, _ListeFilms)
            'Fermeture du fichier
            FluxDeFichier.Close()
        End Sub
     
    #End Region
     
    #Region "Section recherche"
     
        Private Sub RemplissageChampsRecherche()
            'Fonction utilisée plus tard pour préremplir les DDL de genres, réalisateurs…
        End Sub
     
        Private Sub BT_RECHERCHE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_SEARCH.Click
            Recherche()
        End Sub
     
        Private Sub Recherche()
     
            'On vide la liste et on la reremplit
            listbox_films.Items.Clear()
            'Parcourt les films de la bibliothèque
            For Each FilmALister As Film In _ListeFilms
     
                If TXT_SEARCH.Text <> "" Then
                    If FilmALister.Nom.Contains(TXT_SEARCH.Text) Then
                        listbox_films.Items.Add(FilmALister)
                    End If
                End If
            Next
        End Sub
     
    #End Region
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Serialisation()
        End Sub
    End Class
     
     
    Public Class Film
        Private _Nom As String
        Public Property Nom As String
            Get
                Return _Nom
            End Get
            Set(ByVal value As String)
                _Nom = value
            End Set
        End Property
     
        Private _Synopsis As String
        Public Property Synopsis As String
            Get
                Return _Synopsis
            End Get
            Set(ByVal value As String)
                _Synopsis = value
            End Set
        End Property
     
        Private _NotePerso As Integer
        Public Property NotePerso As Integer
            Get
                Return _NotePerso
            End Get
            Set(ByVal value As Integer)
                _NotePerso = value
            End Set
        End Property
     
        Private _Duree As Integer
        Public Property Duree As Integer
            Get
                Return _Duree
            End Get
            Set(ByVal value As Integer)
                _Duree = value
            End Set
        End Property
     
        Private _Statue As String
        Public Property Statue As String
            Get
                Return _Statue
            End Get
            Set(ByVal value As String)
                _Statue = value
            End Set
        End Property
     
        Private _Type As String
        Public Property Type As String
            Get
                Return _Type
            End Get
            Set(ByVal value As String)
                _Type = value
            End Set
        End Property
     
        Private _IMGURL As String
        Public Property IMGURL As String
            Get
                Return _IMGURL
            End Get
            Set(ByVal value As String)
                _IMGURL = value
            End Set
        End Property
     
        Public Sub New(ByVal Nom As String, ByVal Synopsis As String, ByVal NotePerso As Integer, ByVal Duree As Integer, ByVal Statue As String, ByVal Type As String, ByVal IMGURL As String)
            _Nom = Nom
            _Synopsis = Synopsis
            _NotePerso = NotePerso
            _Duree = Duree
            _Statue = Statue
            _Type = Type
            _IMGURL = IMGURL
        End Sub
     
        Public Sub Update(ByVal Nom As String, ByVal Synopsis As String, ByVal NotePerso As Integer, ByVal Duree As Integer, ByVal Statue As String, ByVal Type As String, ByVal IMGURL As String)
            _Nom = Nom
            _Synopsis = Synopsis
            _NotePerso = NotePerso
            _Duree = Duree
            _Statue = Statue
            _Type = Type
            _IMGURL = IMGURL
        End Sub
     
        'Je surcharge le Tostring
        Public Overrides Function ToString() As String
            Return _Nom
        End Function
    End Class

    Je n'ai vraiment plus aucune idée, j'ai essayer tout plein de manip' de mon niveau mais en vain.



    Cordialement,

    Grano'



    Merci pour votre aide et votre temps consacré

  2. #2
    Membre éprouvé
    Avatar de dkmix
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    619
    Détails du profil
    Informations personnelles :
    Localisation : Jamaïque

    Informations forums :
    Inscription : Septembre 2007
    Messages : 619
    Points : 924
    Points
    924
    Par défaut
    Bonjour,
    La réponse est dans le titre. Un objet sérialisable doit avoir un constructeur par défaut sans paramètre.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Public Class Film
    ...
    Public Sub New()
            _Nom = String.Empty
            _Synopsis = String.Empty
            _NotePerso = 0
            _Duree = 0
            _Statue = String.Empty
            _Type = String.Empty
            _IMGURL = String.Empty
        End Sub
    ...
    End Class

  3. #3
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Toujours le même message d'erreur mais maintenant quand je créer une nouvelle fiche tout est vide. Si vous voulez plus de screens dites le moi :o

    Merci pour votre aide et votre temps passé

  4. #4
    Membre éprouvé
    Avatar de dkmix
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    619
    Détails du profil
    Informations personnelles :
    Localisation : Jamaïque

    Informations forums :
    Inscription : Septembre 2007
    Messages : 619
    Points : 924
    Points
    924
    Par défaut
    Et sans l'override de la fonction ToString ?

  5. #5
    Candidat au Club
    Femme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Maintenant il me met WindowsApplication1.Film en nom dans la listbox, il laisse les textbox vides dans le cadre des films, tenez voici des screens pour aider un peu a comprendre le logiciel :

    http://puu.sh/6yMH8 <= Accueil
    http://puu.sh/6yMHE <= Creation d'une fiche avec le bouton en haut a gauche nouvelle fiche
    http://puu.sh/6yMIh <= Une fois validation de la nouvelle fiche
    http://puu.sh/6yMIH <= Quand on clique sur une fiche
    http://puu.sh/6xPW1.JPG <= L'erreur de serialisation quand on quitte / appuie sur sauvegarder.

    Voila voila si vous en voulez plus dite le moi, je suis a court d'idées là :-(

Discussions similaires

  1. Pas de compilation sans constructeur sans argument!
    Par bertry dans le forum Débuter
    Réponses: 3
    Dernier message: 28/12/2011, 11h33
  2. je ne trouve pas connexion réseau sans fil
    Par unix27 dans le forum Hardware
    Réponses: 6
    Dernier message: 29/08/2006, 22h10
  3. Impossible de sérialiser l'attribut de session
    Par dehbi dans le forum Struts 1
    Réponses: 8
    Dernier message: 15/04/2006, 16h17
  4. Réponses: 4
    Dernier message: 23/12/2005, 19h35
  5. Réponses: 5
    Dernier message: 04/11/2004, 15h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo