[__NSCFString appendString:]: nil argument' error
<p>I was trying to show string values in print preview option.If i didn't enter any text in any of the textfield and while clicking print button the app gets crashed.And the error is [__NSCFString appendString:]: nil argument'.Here is my code</p>

<pre><code>-(NSMutableString*)pageStringToPrint {

    NSMutableString * cnoteString = [[NSMutableString alloc]init];

    [cnoteString setString:@"Class: "];
    [cnoteString appendString:self.cnote.classname];
    [cnoteString appendString:@"\nTeacher: "];
    [cnoteString appendString:self.cnote.teacher];
    [cnoteString appendString:@"\nSource: "];
    [cnoteString appendString:self.cnote.source];
    [cnoteString appendString:@"\nTopic: "];
    [cnoteString appendString:self.cnote.topic];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM-dd-yyyy"];
    NSString *dateString = [dateFormat stringFromDate:self.cnote.date];
    [cnoteString appendString:@"\nDate: "];
    [cnoteString appendString: dateString];  

    cnoteString = [NSMutableString stringWithFormat:@"&lt;div id=\"mainContainer\"&gt;&lt;div id=\"header\"&gt;%@&lt;/div&gt;",[cnoteString kv_encodeHTMLCharacterEntities]];
</code></pre>

<p>This is how i created Self.cnoe.classname</p>

<pre><code>- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self saveCNote ];
    self.classNameTextField.text = self.cnote.classname;
    self.topicTextField.text = self.cnote.topic;
    self.sourceTextField.text = self.cnote.source;
    self.teacherTextField.text = self.cnote.teacher;


    self.essentialQuestionTextView.placeholder = @"Essential Question";
    self.essentialQuestionTextView.layer.cornerRadius = 7.0f;
    self.essentialQuestionTextView .layer.borderColor = [[UIColor grayColor] CGColor];
    self.essentialQuestionTextView.layer.borderWidth= 1.0f;
    self.essentialQuestionTextView.delegate = self;
    self.essentialQuestionTextView.text = self.cnote.essentialQuestion;

    // set the date
    self.dateTextField.delegate = self;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM-dd-yyyy"];
    self.dateTextField.text = [dateFormat    stringFromDate:self.cnote.date];
  }
</code></pre>

<p>Save Cnote:</p>

<pre><code>- (void)saveCNote {

    self.cnote.classname = self.classNameTextField.text;
    self.cnote.topic = self.topicTextField.text;
    self.cnote.source = self.sourceTextField.text;
    self.cnote.teacher = self.teacherTextField.text;


    [self.cnote save];
}
</code></pre>