There are two ways to overcome loneliness. One is by getting involved with other people so you neither are nor feel lonely; the other is by yourself, so that although you are alone, you don't feel lonely. Your question seems to rule out the first route, but the second remains open. Loneliness is not just being alone, it is being unhappy about it. And you may be able to bring yourself to accept being alone in a way that stops the unhappiness. But I would recommend the first route if at all possible. And perhaps your question does not rule it out after all. For even if you are surrounded by other people you may feel lonely, and even though you are surrounded by other people you may need to overcome the feeling by yourself, or at least the impetus must come from you. But I think the way to do that is to engage with people and projects in ways that help you get rid of that lonely feeling.
Robert, this is a good question, but it is hard to answer because people are mean for lots of different reasons. Sometimes people are mean because they aren't thinking about how other people feel. Sometimes they know how other people feel, but just don't care. And sometimes they actually want to hurt other people, and this might be for lots of different reasons, like they are jealous or something. Maybe it is because there are so many different reasons why people may be mean that you are right that all people are sometimes mean. If you are right then that is sad, but we should also remember that at least almost everybody is also sometimes nice, and maybe a lot of people are nice much more often than they are mean.
Why should stupidity be painful? Perhaps because stupidity is an evolutionary disadvantage, and evolutionary pressures should have led us to find evolutionary disadvantages painful so we would avoid them. There are lots of problems with this argument. Ill mention just two. First, the mystery seems supposed to be that we have an evolutionary disadvantage -- the non-painfulness of stupidity. But if you are going to be surprised at the existence of an evolutionary disadvantage, why not just be surprised at the existence of stupidity in the first place? Second, there are many disadvantages that are not painful, such as a genetic predisposition to have a fatal but not painful disease. Not everything that is bad for us hurts.