• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity_lF98_nVJe9di1A · May 06, 2019 at 06:37 PM · filetextassetcsvstreamreader

Using OpenFilePanel at runtime to open a file as a TextAsset to read data is giving NullReferenceException

I am trying to open a csv file using the OpenFile Dialog window which I will convert to a TextAsset and then Split accordingly to read the data, but it keeps giving me a NullReferenceException.

 NullReferenceException: Object reference not set to an instance of an object
 CsvNameSpace.CsvReader+<SetAngles>d__34.MoveNext () (at Assets/CsvReader.cs:92)
 UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
 UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
 CsvNameSpace.CsvReader:Update() (at Assets/CsvReader.cs:80)
 
 

Here is my code:

 using System.Collections;
 using System.IO;
 using System.Text;
 using UnityEditor;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 namespace CsvNameSpace {
 
 
     public class CsvReader : MonoBehaviour
     {
         
 
 
         public string[] fieldsNext;
         public string[] fields;
         public TextAsset csvFile;
         public Button record;
         public GameObject rWrist;
         public GameObject rPalm;
         public GameObject indexMeta;
         public GameObject thumbMeta;
         public GameObject middleMeta;
         public GameObject ringMeta;
         public GameObject pinkyMeta;
         public GameObject index_1;
         public GameObject index_2;
         public GameObject index_3;
         public GameObject indexEnd;
         public GameObject thumb_1;
         public GameObject thumb_2;
         public GameObject thumbEnd;
         public GameObject middle_1;
         public GameObject middle_2;
         public GameObject middle_3;
         public GameObject middleEnd;
         public GameObject ring_1;
         public GameObject ring_2;
         public GameObject ring_3;
         public GameObject ringEnd;
         public GameObject pinky_1;
         public GameObject pinky_2;
         public GameObject pinky_3;
         public GameObject pinkyEnd;
 
         // Update is called once per frame
         int i = 0;
         long previoustime = 0;
 
         void Start()
         {
             record.onClick.AddListener(ChangeScene);
             
             //open file dialog
             var path = EditorUtility.OpenFilePanel("", "","CSV");
             if (path == "")
             {
                 //if no file is chosen then change back to recording scene
                 ChangeScene();
             }
             else
             {
                 StreamReader file = new StreamReader(path);
                 //load file as a TextAsset
                 csvFile = Resources.Load(path) as TextAsset;
                 Debug.Log(path);
             }
         }
 
         void Update()
         {
                 StartCoroutine(SetAngles());
                 i++;
             
         }
 
        
         IEnumerator SetAngles()
         {
             print("Time " + Time.time);
             if (i > 0)
             {
                 //put CSV file into array called records by obtaining each row
                 string[] records = csvFile.text.Split('\n');
       //ERROR OCCURS HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by vickychaudhary8955 · Mar 27 at 01:19 AM

did you get any answers coz i am facing the same thing and if you can help me out it will be grateful.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

106 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityEngine.DefautAsset as TextAsset 1 Answer

Basic Question about TextAssets 0 Answers

Problem reading csv file when last semicolon is missing 0 Answers

Help with reading a text file? 1 Answer

Download and save file from Amazon S3 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges