media->save gives erros I am able to create a media object with the below code 

 $static_media = Media::create([ 
'bundle' =&gt; 'document', 
'uid' =&gt; $current_userid , 
'langcode' =&gt; "en",
'status' =&gt; 1, 
 'name' =&gt; [
    'target_id' =&gt;$title,

  ],
$file_name =&gt; [ 'target_id' =&gt; $fid, 'alt' =&gt; $title, 'title' =&gt; $title, ], ]);


but when I try to do $result=$static_media-&gt;save();  I get the error 

Error: `Call to a member function isEmpty() on null in Drupal\media_entity_document\Plugin\MediaEntity\Type\Document-&gt;getField() (line 43 of profiles\lightning\modules\contrib\media_entity_document\src\Plugin\MediaEntity\Type\Document.php).


How can I debug this to find out what is missing?  I tried putting an echo at that point of the code in the plugin but cannot see anything .  What would you suggest to try to see what field it is looking for at that point?

Thank you .
instead of this part of the array

$file_name =&gt; [ 'target_id' =&gt; $fid, 'alt' =&gt; $title, 'title' =&gt; $title, ], ]);


i had to put the field name , not the file name.

'field_document' =&gt; [ 'target_id' =&gt; $fid, 'alt' =&gt; $title, 'title' =&gt; $title, ], ]);