2
我希望此相對佈局最終會在底部加載廣告。爲什麼會這樣空指針在引用主佈局時出現異常
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
任何想法:
public class Main extends Activity {
RelativeLayout mLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mLayout = (RelativeLayout) findViewById(R.layout.main);
ImageView View = new ImageView(this, null); //example view
mLayout.addView(View);
然後空指針下方時mLayout被稱爲
RelativeLayout.LayoutParams rparams = (LayoutParams) mLayout.getLayoutParams();
E/AndroidRuntime(4066): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.name.project/com.name.project.Main}: java.lang.NullPointerException
XML的佈局發生H ERE?