The comments about the famine being convenient aren't wrong (I'm not gonna tag the guy from a 2 year old discussion), but there's plenty of factors not mentioned here that could be affecting matters. The King doesn't directly command the farmers what to plant in what field, this isn't Age of Empires. There's a dozen layers of foreman, village mayor, lesser noble, higher noble, etc between a farmer and the king, and each of them can be of varying competency levels and/or simply looking at their own individual situations rather than the kingdom as a whole. Let's take for example Agriculturalist A, owner of a reasonably sized field in a decently fertile part of the kingdom. He used to grow strawberries to sell at the local produce market (ignore for a moment the difference in needs between strawberries and cotton, I don't know many cash crops), but times have changed so now he grows a few potatoes to feed himself (not enough to export) and has dedicated the rest of his field to cotton. He doesn't have a food problem.
Next is Baron B, owner of 200 fields suspiciously similar to Agriculturalist A's. His farmers have been planting cotton the past few seasons, which sells for really high at the neighboring textile industry city, which makes him a rich baron who doesn't have to worry about going hungry regardless of food prices. He doesn't see a people either.
His superior, the Count C, could lean on him if he wanted to, but he has an entire city with five attached villages to oversee, as well as the responsibility to raise a regiment of horse when the king calls. The Baron pays generous dues and has never caused problems, so he sees no reason to intervene in his affairs (especially since if he did, the rich Baron could cause all kinds of trouble behind his back at the capital). He is aware the prices of food in his city are rising, but he blames the neighboring country's traders for being money-grubbing savages who try to bleed his people alive. Anyway, it can't be that bad if he can still eat.
HIS superior, Duke D, one of the three more powerful people in the country, can see there's an emerging food shortage problem in the country, but he has no idea what to do to stop it. His training has been all about warfare and tactics (and indeed he is a great strategist on the field) and he lets his retainers handle the day to day affairs of his dukedom.
And thus we get to the King, who has been made aware there's less food coming in the country now than before the war and, in an effort to fix that, has signed a very disadvantageous trade deal with the neighboring kingdom to import more food. After all, what more can he do? It's not like he has the time, agricultural knowledge, or even the authority to just waltz into a farming village and order them to just plant rice instead of cotton, if he ever even came up with the idea. That would cause no amount of scandal and ill feeling to his subordinates who own and/or manage those lands in his name (depending on the exact flavor of feudalism going on in this kingdom).
Enter isekai'd hero, stage left. He doesn't know anything about the kingdom, its traditions, people, who's who, etc. He can just look at spreadsheets (or what passes for medieval spreadsheets, I can't imagine they had itemised receipts or detailed import/export ledgers back then), figure out what needs producing, and just order it to happen, just like a videogame... because to him it might as well be. Nevermind the dude being trained specifically as an Agricultural Government Official, just being an unconnected stranger who can do math is enough to kick-start a solution. (Of course, the upcoming political fallout is another issue).