After some testing, I was able to replicate the issue:
**A form redirects to a view without a menu item or redirects to itself relatively to a url like this one:
component/mycomponent/myview
(It doesn't matter if the view has a menu item or not, this is just stupid Joomla routing.)**
Therefore the following has to be done to prevent the error:
1) the view has to be linked with an menu item in the Joomla backend
2) the url to the form in the frontend should be /menu-alias
3) the forms action shouldn't redirect to another view, better be empty
4) the form should contain hidden inputs with the task
Then your post and save redirection in the controller works like a charm, because you are operating within the menu item context (url).
But, if you redirect to another view or via JRoute to the same view without saving the current item id, you will leave the menu item context ("component/mycomponent/myview").
This happens a lot in Joomla, because the current router system doesn't check the given url against the menu items in the database. To prevent that, you can do the following actions:
1) Extend the router of your component with a function which searches the menu item table for the current url and returns the item id / menu item. (I have done that already in the past and it works.)
2) Add a hidden fields in your form which contains the item id, task and target view (the correct way in Joomla to route).
3) Redirect urls like "component/mycomponent/myview" to the correct url path.
4) You can set fallbacks in the component params for every view. This will chain the item id to the component params and not the views to an url path.
View1 -> Dropdown -> Select Chained Menu Item
In controller:
$itemId = $params->get( $mycurrentviewname );
Don't use the $menu->getActive() if not absolutely necessary, because of the stupid Joomla routing system. I am recommending to set the menu item manually somehow.
Back to question:
How I said, your error is somewhere in the beginning of routing. This could be simply your url which leads to your form or a redirect after submitting the form to a view without a menu item or to a url which doesn't contain an itemId.
Proof:
Add this to your save function between $itemid and $message:
if(empty($itemId)){
$itemId = $app->input->get('Itemid', $itemId,'int');
$active = $menu->getItem($itemId);
}
Then add "&task=save&Itemid=101" to the url which returns your error message.
(Change 101 to your item id!)
You should be redirected correctly now.