Victoria,

The cause of this exception appears in logcat:

07-16 19:40:45.124: ERROR/AndroidRuntime(225): Caused by:
java.lang.NullPointerException
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
com.mobilevideoeditor.moved.EditGalleryView
$VideoAdapter.getCount(EditGalleryView.java:73)

Looks like vidUris is null.

Set a breakpoint and debug - looks like adapter's getCount() gets called before the information (vidUris) becomes available.

-- Kostya

17.07.2010 0:49, Victoria пишет:
Hi,

I am trying to load videos from my emulated sdcard into my implemented
GridView, it worked fine before, when I used the GridView example from
Google...but now I get a Force close error when I try to open the app.

The entire app works (or rather should work) like this a TabView is
launched that includes 2 tabs (GalleryView.java and main.xml), each
tab loads a GridView (EditGalleryView.java and ShareGalleryView.java).
Before I tried loading videos into the gridView I simply used the
GridView example as starting point. Now on basis of this example I am
trying to load videos into my GridView from the sdcard, which
apparently seems to cause a Force Close Error.

If someone could help me find the problem that's causing this, it
would be great because I really don't know what's wrong now ...
Thanks in Advance

Here is the code I use:

The Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
       package="com.mobilevideoeditor.moved"
       android:versionCode="1"
       android:versionName="1.0">
     <application android:icon="@drawable/icon" android:label="@string/
app_name">
                <activity android:name=".EditGalleryView"
                             android:label="@string/app_name"
                             android:theme="@android:style/
Theme.NoTitleBar">
                 <intent-filter>
                     <action android:name="android.intent.action.PICK"/
                 </intent-filter>
              </activity>
            <activity android:name=".ShareGalleryView"
                             android:label="@string/app_name"
                             android:theme="@android:style/
Theme.NoTitleBar">
                     <intent-filter>
                         <action
android:name="android.intent.action.SEND"/>
                     </intent-filter>
                 </activity>
            <activity android:name=".GalleryView"
                         android:label="@string/app_name"
                         android:theme="@android:style/
Theme.NoTitleBar">
                 <intent-filter>
                         <action
android:name="android.intent.action.MAIN" />
                     <category
android:name="android.intent.category.LAUNCHER" />
                 </intent-filter>
            </activity>
     </application>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>

The GalleryView.java:

package com.mobilevideoeditor.moved;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class GalleryView extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     Resources res = getResources(); // Resource object to get
Drawables
     TabHost tabHost = getTabHost();  // The activity TabHost
     TabHost.TabSpec spec;  // Reusable TabSpec for each tab
     Intent intent;  // Reusable Intent for each tab

     // Create an Intent to launch an EditGallery for the tab (to be
reused)
     intent = new Intent().setClass(this, EditGalleryView.class);

     // Initialize a TabSpec for each tab and add it to the TabHost
     spec = tabHost.newTabSpec("edit").setIndicator("Edit",
                       res.getDrawable(R.layout.ic_tab_edit))
                   .setContent(intent);
     tabHost.addTab(spec);

     intent = new Intent().setClass(this, ShareGalleryView.class);
     spec = tabHost.newTabSpec("share").setIndicator("Share",
                       res.getDrawable(R.layout.ic_tab_share))
                       .setContent(intent);
tabHost.addTab(spec);

     tabHost.setCurrentTab(0);
}
}

The EditGalleryView.java (which seems to cause my problem):

package com.mobilevideoeditor.moved;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.VideoView;




public class EditGalleryView extends Activity {
     Uri[] vidUris;
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.videogrid);

         GridView vGrid=(GridView) findViewById(R.id.vgrid);
         vGrid.setAdapter(new VideoAdapter(this));

         Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;

         Log.d("EditGalleryView", "uri:"+uri);
  String[] projection = {
                 MediaStore.Video.Media.DESCRIPTION,
                 MediaStore.Video.Media.DATA
     };

         Cursor c = this.managedQuery(uri, projection, null, null,
                 MediaStore.Video.Media.DATE_ADDED);
                          Log.d("EditGalleryView", "vids available:"
+c.getCount());

                          ArrayList<Uri>  experimentVids = new
ArrayList<Uri>();


                              if (c.getCount() != 0) {
                                  c.moveToFirst();
                                  //
experimentVids.add(Uri.parse(c.getString(1)));
                                  while (c.moveToNext()) {

experimentVids.add(Uri.parse(c.getString(1)));

                                   }
                       }
                              Log.d("ClassName",
"experimentVids.length:" +experimentVids.size());
                                                   if
(experimentVids.size() != 0) {
                                                     vidUris = new
Uri[experimentVids.size()];
                                                       for (int i = 0;
i<  experimentVids.size(); i++) {
                                                           vidUris[i] =
experimentVids.get(i);
                                                       }

Log.d("EditGalleryView", "vidUris:"+vidUris.length);
                                                   }
                                               }


     public class VideoAdapter extends BaseAdapter {
         private Context mContext;

         public VideoAdapter(Context c) {
             mContext = c;
         }

         public int getCount() {
             //return mThumbIds.length;
             return vidUris.length;
         }

         public Object getItem(int position) {
             //return null;
             return position;
         }

         public long getItemId(int position) {
             //return 0;
             return position;
         }

         // create a new ImageView for each item referenced by the
Adapter
         public View getView(int position, View convertView, ViewGroup
parent) {
            VideoView videoView;
             if (convertView == null) {  // if it's not recycled,
initialize some attributes
                 videoView = new VideoView(mContext);
                 videoView.setVideoURI(vidUris[position]);
                 videoView.setLayoutParams(new
GridView.LayoutParams(85, 85));
                //
videoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                 videoView.setPadding(8, 8, 8, 8);
             } else {
                 videoView = (VideoView) convertView;
             }

           //  imageView.setImageResource(mThumbIds[position]);
             return videoView;
         }

And this is my LogCat Error Output:

07-16 19:40:45.074: ERROR/AndroidRuntime(225): Uncaught handler:
thread main exiting due to uncaught exception
07-16 19:40:45.124: ERROR/AndroidRuntime(225):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.mobilevideoeditor.moved/
com.mobilevideoeditor.moved.GalleryView}: java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.mobilevideoeditor.moved/
com.mobilevideoeditor.moved.EditGalleryView}:
java.lang.NullPointerException
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2496)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.os.Handler.dispatchMessage(Handler.java:99)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.os.Looper.loop(Looper.java:123)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
dalvik.system.NativeStart.main(Native Method)
07-16 19:40:45.124: ERROR/AndroidRuntime(225): Caused by:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.mobilevideoeditor.moved/
com.mobilevideoeditor.moved.EditGalleryView}:
java.lang.NullPointerException
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2496)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.LocalActivityManager.moveToState(LocalActivityManager.java:
127)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.LocalActivityManager.startActivity(LocalActivityManager.java:
339)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.widget.TabHost
$IntentContentStrategy.getContentView(TabHost.java:648)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.widget.TabHost.setCurrentTab(TabHost.java:320)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.widget.TabHost.addTab(TabHost.java:213)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
com.mobilevideoeditor.moved.GalleryView.onCreate(GalleryView.java:28)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     ... 11 more
07-16 19:40:45.124: ERROR/AndroidRuntime(225): Caused by:
java.lang.NullPointerException
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
com.mobilevideoeditor.moved.EditGalleryView
$VideoAdapter.getCount(EditGalleryView.java:73)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.widget.GridView.setAdapter(GridView.java:128)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
com.mobilevideoeditor.moved.EditGalleryView.onCreate(EditGalleryView.java:
28)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
07-16 19:40:45.124: ERROR/AndroidRuntime(225):     ... 20 more



--
Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to