TGraphAsymmErrors - <Handler Interpreter Exception>

I am trying to call a file using TGraphAsymmErrors using the following lines -

c1 = new TCanvas (“c1”, " ");
TFile f1 = new TFile("/afs/");
TGraphAsymmErrors * gr = (TGraphAsymmErrors

It is showing the following error -
Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.
warning: null passed to a callee that requires a non-null argument [-Wnonnull] gr->Draw(“AP”);

Any hints are appreciated !
Thank you

Double check hat the name
is correct! Do you really have a TGraphAsymmErrors object with such a long name containing special characters? You even have the f1->ls() in your code - does it print this name?

a) don’t use special characters like | and + in names. They cause problems, for example you can’t use these these names directly in the root command line.
b) Always check the return value of Get() and don’t use unsafe C style casts. Instead, use

TGraphAsymmErrors *gr;
f1->GetObject("name of the object", gr);
if (gr == nullptr) 
    cout << "Requested object does not exist or has an incompatible type\n";

It works now ! Thank you, I will follow the advice in future.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.