1

这是我想在创建时加载的 xml 文件。但它不会加载并反过来返回一个空值。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        android:orientation="vertical"
         android:background="@drawable/plainbackground" 
         android:layout_width="fill_parent" android:layout_height="fill_parent"
      xmlns:android="http://schemas.android.com/apk/res/android">
        <GridView android:gravity="center" 
            android:id="@+id/gridview" 
            android:scrollbars="vertical" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:horizontalSpacing="4.0dip" 
            android:verticalSpacing="2.0dip" 
            android:stretchMode="columnWidth" 
            android:columnWidth="100.0dip" 
            android:numColumns="auto_fit" 
            android:layout_weight="1.0" />
        <Button 
            android:layout_gravity="center" 
            android:id="@+id/done" 
            android:background="@drawable/done" 
            android:visibility="gone" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" />

    </LinearLayout>

我调用这个文件的活动如下。相反,每次我调用此活动时应用程序都会崩溃。

 public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
   setContentView( com.example.application1.R.layout.activity_multiphoto_);
   fillAlbums();
    this.options = new DisplayImageOptions.Builder().showStubImage(R.drawable.ic_gallery).showImageForEmptyUri(R.drawable.ic_gallery).cacheInMemory().cacheOnDisc().build();
    this.albumAdapter = new AlbumAdapter(this.mAlbumsList);
    this.gridView = ((GridView)findViewById(R.id.gridview));
    this.done = ((Button)findViewById(R.id.done));
    this.gridView.setAdapter(this.albumAdapter);
    this.gridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
      public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        if (MultiPhotoSelectActivity.this.isAlbumView)
        {
          MultiPhotoSelectActivity.this.isAlbumView = false;
          MultiPhotoSelectActivity.this.fillGallery(((MultiPhotoSelectActivity.Album)MultiPhotoSelectActivity.this.mAlbumsList.get(paramAnonymousInt)).albumId);
        }
      }
    });
    this.done.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        ArrayList localArrayList = MultiPhotoSelectActivity.this.imageAdapter.getCheckedItems();
        Intent localIntent = new Intent(MultiPhotoSelectActivity.this, CreateSlideActivity.class);
        localIntent.putExtra("list", localArrayList);
        System.out.println(" " + localArrayList);
        MultiPhotoSelectActivity.this.setResult(-1, localIntent);
        MultiPhotoSelectActivity.this.finish();
      }
    });
  }
  private void fillAlbums()
  {
    this.isAlbumView = true;
    this.mAlbumsList = new ArrayList();
    String[] arrayOfString = { "_data", "_id", "bucket_display_name", "bucket_id" };
    Cursor localCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, arrayOfString, null, null, null);
    HashSet localHashSet = new HashSet();
    for (int i = 0;; i++)
    {
      if (i >= localCursor.getCount()) {
        return;
      }
      Album localAlbum = new Album();
      localCursor.moveToPosition(i);
      int j = localCursor.getColumnIndex("_data");
      int k = localCursor.getColumnIndex("bucket_display_name");
      int m = localCursor.getColumnIndex("bucket_id");
      localCursor.getColumnIndex("_id");
      String str = localCursor.getString(k);
      localAlbum.setAlbumName(str);
      localAlbum.setImageUrl(localCursor.getString(j));
      localAlbum.albumId = localCursor.getString(m);
      if (localHashSet.add(str)) {
        this.mAlbumsList.add(localAlbum);
      }
      System.out.println("=====> BUCKET_DISPLAY_NAME => " + localCursor.getString(localCursor.getColumnIndex("bucket_display_name")));
    }
  }

请帮我解决这个问题..

logcat如下

09-09 15:46:33.294: E/AndroidRuntime(378): FATAL EXCEPTION: main
09-09 15:46:33.294: E/AndroidRuntime(378): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.application1/com.example.application1.MultiPhotoSelectActivity}: java.lang.NullPointerException
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.ActivityThread.access$1500(ActivityThread.java:122)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.os.Looper.loop(Looper.java:132)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.ActivityThread.main(ActivityThread.java:4025)
09-09 15:46:33.294: E/AndroidRuntime(378):  at java.lang.reflect.Method.invokeNative(Native Method)
09-09 15:46:33.294: E/AndroidRuntime(378):  at java.lang.reflect.Method.invoke(Method.java:491)
09-09 15:46:33.294: E/AndroidRuntime(378):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
09-09 15:46:33.294: E/AndroidRuntime(378):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
09-09 15:46:33.294: E/AndroidRuntime(378):  at dalvik.system.NativeStart.main(Native Method)
09-09 15:46:33.294: E/AndroidRuntime(378): Caused by: java.lang.NullPointerException
09-09 15:46:33.294: E/AndroidRuntime(378):  at com.example.application1.MultiPhotoSelectActivity.fillAlbums(MultiPhotoSelectActivity.java:63)
09-09 15:46:33.294: E/AndroidRuntime(378):  at com.example.application1.MultiPhotoSelectActivity.onCreate(MultiPhotoSelectActivity.java:118)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
09-09 15:46:33.294: E/AndroidRuntime(378):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
09-09 15:46:33.294: E/AndroidRuntime(378):  ... 11 more
4

0 回答 0