0

我有我的活动代码:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.movies_category);
      GridView gridView = (GridView) findViewById(R.id.grid_view);//Here It's retuning Null Value For Simulator Tab
   // Instance of ImageAdapter Class
      gridView.setAdapter(new ImageAdapter(this));
}

movies_category.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/screen_background">      


 <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:layout_alignBottom="@+id/linearLayout01"
                android:layout_marginBottom="55dp"> 



<ImageView 
                  android:id="@+id/imageView1"
                  android:layout_width="fill_parent"
                  android:layout_height="50dp"
                  android:src="@drawable/banner"
                  android:layout_alignParentTop="true"
                  android:scaleType="fitXY"/>

<GridView 
    android:id="@+id/grid_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:columnWidth="90dp"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="10dp"
    android:gravity="center"
    android:stretchMode="columnWidth" >  

</GridView>
</LinearLayout>
</RelativeLayout>

当我尝试在 Nexusone Emulator 上执行应用程序时,我能够成功显示我的 GridView(gridView 对象有一个值)

但是当我尝试在 Tab Emulator 上执行时,相同的代码,我无法显示 GridView(gridView 对象显示 Null)

堆栈跟踪:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity 

    ComponentInfo{com.tel.movies/com.tel.movies.MovieCategoryViewAcivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
        at android.app.ActivityThread.access$2300(ActivityThread.java:125)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
        at com.oone.movies.MovieCategoryViewAcivity.onCreate(MovieCategoryViewAcivity.java:49)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity

任何人都可以帮助我吗?

4

1 回答 1

1

对于具有不同屏幕分辨率和尺寸的 Tabs Simulator 以及 Mobile Simulator,我们在 Android 中有单独的布局文件夹,例如(layout、layout-land、layout-large、layout-large-land 等......)我们需要定义我们定义的布局 xml 文件..

在我的查询中,我需要在所有 LayoutFolders 中定义 movies_category.xml 文件才能成功执行应用程序

于 2013-03-21T07:28:09.377 回答