Yii2 Trying to get property of non-object

Why am I getting this error and how do I resolve it


non object.PNG

 public function actionCourseTopics($csid)


        //$courseMaster = Course::findOne($csid);

       // $coursetopics = CourseStructure::find()->where(['b.building_id'=>$csid])->join('join','building_tariff bt', 'bt.tariff_id = fee.tariff_id')->join('join','building b', 'b.tariff_id = bt.tariff_id AND b.building_id')->one();

        $coursetopics = CourseStructure::find()->where(['structure_course_id' => $csid])->One();

        $csidx = $coursetopics->structure_course_id; 


        $searchModel = new CourseStructureSearch();

        $dataProvider = $searchModel->searchtopics(Yii::$app->request->queryParams, $csidx);



        return $this->render('course-topics', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,


The error is here:

$csidx = $coursetopics->structure_course_id; 

because $coursetopics assignment is null, because it is not found is db using "structure_course_id=$csid" .

Check also that One() has to be typed as one().

Thanks a lot, I found out that it is null. How do I write a statement not to display this error, but to notify the user that it is not found