Question

i am having a little problem, VS gives me 2 warnings about two values (int[] and string[]) that are null because they are never assigned, but im sure i assigned them, this is the part of the code that is relevant to my problem:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using System.IO;
namespace DA_Story_Editor
{
public partial class Form1 : ComponentFactory.Krypton.Toolkit.KryptonForm
{
    public Form1()
    {
        InitializeComponent();
    }
    int[] pntrs;
    string[] Strs;

    private void ReadFile(string path1)
    {

        FileStream stream = new FileStream(path1, FileMode.Open, FileAccess.Read);

        for (int i = 0; i < Pntrnum; i++)
        {
            stream.Position = Pntrstrt;
            stream.Read(data, 0, data.Length);
            pntrs[i] = BitConverter.ToInt32(data, 0);
        }
        for (int i = 0; i < Pntrnum; i++)
        {
            byte[] sttrings = new byte[pntrs[i + 1] - pntrs[i]];
            stream.Position = pntrs[i];
            stream.Read(sttrings, 0, sttrings.Length);
            Strs[i] = Encoding.GetEncoding("SHIFT-JIS").GetString(sttrings);

            ListViewItem item = new ListViewItem(new string[]
                {
                    pntrs[i].ToString("X"),
                    Strs[i],
                    Strs[i],
                });
            listView1.Items.AddRange(new ListViewItem[] {item});
        }
    }
}
}

im not sure why it does give me those warnings, and btw it also gives me a "NullReferenceException" on the line: pntrs[i] = BitConverter.ToInt32(data, 0);

Était-ce utile?

La solution

You're never constructing and assigning the variable itself - but you try to use the array:

// Need to add:
pntrs = new int[Pntrnum];

for (int i = 0; i < Pntrnum; i++)
{
    stream.Position = Pntrstrt;
    stream.Read(data, 0, data.Length);
    pntrs[i] = BitConverter.ToInt32(data, 0);
}

// Need to add:
Strs = new string[Pntrnum];

for (int i = 0; i < Pntrnum; i++)
{
    byte[] sttrings = new byte[pntrs[i + 1] - pntrs[i]];
    stream.Position = pntrs[i];
    stream.Read(sttrings, 0, sttrings.Length);
    Strs[i] = Encoding.GetEncoding("SHIFT-JIS").GetString(sttrings);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top