Instanitate an object inside a parent with no errors or gameobject error

So i ran onto this problem And i can’t seem to know how to fix it.

I Want It To Instantiate Into A Parent Without GameObject Errors Like Having The GameObject Put In A Different GameObject Than What I Needed.

GameObject gameobj;
void Start()
{
   Instantiate(gameobj);
// make it inside a parent
//not run into gameobject errors
//can be repeated
}

im sorry if this is too much
im a bit beginner in these things.
thanks
Zuku

public void InstantiateObjectInParent (GameObject prefab, GameObject parent){
GameObject instance = Instantiate (prefab);
instance.transform.parent = parent.transform;
}