【问题标题】:Android GridView is Returning Null Value on Tab Simulator [duplicate]Android GridView 在选项卡模拟器上返回空值 [重复]
【发布时间】:2013-03-20 15:58:04
【问题描述】:

我有我的活动代码:

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(显示 Null 的 gridView 对象)

堆栈跟踪:

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

谁能帮帮我?

【问题讨论】:

    标签: android android-layout android-intent android-widget


    【解决方案1】:

    对于具有不同屏幕分辨率和尺寸的选项卡模拟器以及移动模拟器,我们在 Android 中有单独的布局文件夹,例如(布局、布局-土地、布局-大、布局-大-土地等......)在那里我们需要定义我们定义的 Layout xml Files..

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-03
      • 2012-12-05
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多