Berkeley's first attempt at refuting philosophical materialism comes through his attack on Locke's distinction between the primary and secondary qualities of objects. According to Locke, primary qualities are those that exist in the object itself, independently of our perceptions. Examples of such qualities would be bulk, number, and motion. Locke supports his claim by arguing that no matter how much one altered an object it would still retain all its primary qualities.
Secondary qualities, on the other hand, are powers possessed by objects that cause us to have ideas of color, smell, taste, sound, and texture. In other words, these qualities exist in the mind and not in the object itself. Locke illustrates this point by asking us to consider why the same water can feel cold to one person but warm to another. Because the water cannot be both hot and cold, the ideas of their heat or coldness cannot be in the water itself; they must be in our minds, caused by the powers generated by the object. (In this case, the water).
Berkeley attempts to refute Locke by abolishing what he sees as his totally unnecessary distinction between primary and secondary substances. As an arch immaterialist, someone who doesn't believe in the existence of matter, Berkeley argues that all qualities are, in Locke's terms, secondary qualities in that they exist in the mind and not in the objects themselves. Berkeley doesn't deny the existence of objects, to be sure; it's just that he thinks they are ideas, not collections of matter.
Berkeley develops his argument against materialism by holding that we can only perceive perceptions, not what may or may not be causing them. As we can only perceive perceptions, which are ideas, not things, there is no logical reason for us to believe in the existence of a material world. Berkeley expresses his most important idea in the Latin expression esse est percipi: "To be is to be perceived". In other words, if something isn't perceived, then it doesn't exist. As the material world cannot be perceived, for the reasons just given, then it logically follows that it doesn't exist.
Contrary to a popular misconception, Berkeley isn't arguing that the world around us is just a dream or some kind of mirage. On the contrary, it's every bit as real as we think it to be. But it's a real world consisting of ideas—ours and God's—and not of matter.