Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
This question was closed Jul 04, 2017 at 06:46 PM by hexagonius for the following reason:

https://docs.unity3d.com/Manual/NullReferenceException.html

avatar image
0
Question by dovelavittoria · Jul 04, 2017 at 06:21 PM · unity 5scripting problemdebuggingruntime-errorcs

NullReferenceException (Updated)

Hi guys, I am new in game development. I am attempting to send an email through input fields but I have been receiving NullReferenceException when I click the Submit button.

Here are my codes:

  using UnityEngine;
     using UnityEngine.UI;
     using UnityEngine.SceneManagement;
     using System.Collections;
     using System;
     using System.Net;
     using System.Net.Mail;
     using System.Net.Security;
     using System.Security.Cryptography.X509Certificates;
 
 [RequireComponent(typeof(InputField))]
 public class FeedbackForm : MonoBehaviour {
 
 InputField emailInputField;
 InputField subjectInputField;
 InputField messageInputField;
 
 void Start()
 {
 emailInputField = GetComponent();
 subjectInputField = GetComponent();
 messageInputField = GetComponent();
 }
 
 void SendTheMail(string text)
 {
 MailMessage mail = new MailMessage();
 
 mail.From = new MailAddress("censoredmail@gmail.com");
 mail.To.Add("censored@gmail.com");
 mail.Subject = "Test Mail";
 mail.Body = text;
 
 SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
 smtpServer.Port = 587;
 smtpServer.Credentials = new System.Net.NetworkCredential("censored@gmail.com", "censored") as ICredentialsByHost;
 smtpServer.EnableSsl = true;
 ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 { return true; };
 smtpServer.Send(mail);
 Debug.Log("success");
 } 
 
 
 public void OnBackToMainMenuClick()
 {
 SceneManager.LoadScene("Mainpage");
 }
 
 void OnSubmitButtonClick()
 {
 SendTheMail(messageInputField.text);
 }
 
 }

Can you guys help me to point out where is the mistake and how to fix that? Your help is greatly appreciated. Thank you

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

  • Sort: 
avatar image
0

Answer by merkaba48 · Jul 04, 2017 at 06:36 PM

The error should mention on what line the exception is being raised; that's your starting point.

The NullReferenceException is caused by trying to perform actions on an object that is 'null', i.e. hasn't been initialized yet, or the initialization failed.

As you are doing networking stuff, this is out of my area of expertise, but it's possible that something in your SendTheMail function takes a little bit of time to 'retrieve' an object if it has to communicate over the network before it can create the object. That's just speculation, but something to think about.

The first thing to do is to find out where it's failing; so check the error message, double-click it, and it'll take you to the line of code where it failed (if its in your scripts). The next thing to do, if you still don't know exactly what's wrong, is to debug the script by putting a breakpoint in at a point you think should definitely work OK, attaching to Unity & running, then stepping through the code and confirming the values are what you expect them to be.

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

Follow this Question

Answers Answers and Comments

159 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 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

How do I make a script wait X time? 1 Answer

Problem with Score/Highscore script 0 Answers

How to assign GameObject to Script? 1 Answer

InvalidOperationException thrown 0 Answers

how do I rezolve "look rotation viewing vector is zero"? 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