Before you can address the issue, you must understand the issue.
Some simple debugging is all it takes to understand the issue. Just start at the point where you have a known state, and work backwards until you find out why
data is null.
Your known state here is that
data is null. You know this because of the
Now, start working backwards. Where does
data get set?
It gets set on the line above,
data is null,
cs.CampaignAttended__c must be null.
Continue to work backwards through your code.
Eventually, you reach the declaration and initialization of the
Contactsample__c cs=new Contactsample__c();
You don't set
cs.CampaignAttended__c anywhere between initializing the
cs variable, and when you set your
data variable using
cs.CampaignAttended__c. It's only natural that this variable would be null.
How you would go about making this
data variable not be null really depends on where this snippet of code is used (and the purpose it's for). The solution here is different if you're using this in a Visualforce controller, compared to if it's being used in a trigger.
About all we can say with the information that you've given us is that your second line,
Contactsample__c cs=new Contactsample__c();, is not what you want to do here. This variable should either be fed from the results of a query, input from a Visualforce page/Lightning component, or from a trigger context variable.
For sake of completeness, you're getting the Null Pointer Exception because
data = null, and
null contains no methods, attributes, or properties.