It's simple
See E = GM/ r^3 r
= 4/3 pi
r .......................... ( 1 ) ( M is the mass enclosed )
fist suppose that the cavity was not there . And we are interested in finding E at the point p from the centre of the cavity . The point that we are considering is at r from the centre of the big sphere .
So we can write
r = p + l ........................ ( 2 )
now we can write that
E ( due to solid sphere ) = E ( due to sphere with its cavity ) + E ( due to solid cavity )
so, E ( due to sphere with its cavity )
= E ( due to solid sphere ) - E ( due to solid cavity ) .............. ( 3 )
Now using ( 1 ) & ( 3 )
we have reqd E = 4/3 pi

(
r -
p ) = 4/3 pi
l ( from ( 2 ) ) which is constant throughout the cavity