0

07-23 05:01:10.925: E/AndroidRuntime(4520): 致命的な例外: メイン 07-23 05:01:10.925: E/AndroidRuntime(4520): java.lang.RuntimeException: アクティビティ ComponentInfo{nsixty をインスタンス化できません。 crew.app/nsixty.crew.app.gallery}: java.lang.NullPointerException 07-23 05:01:10.925: E/AndroidRuntime(4520): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) で 07 -23 05:01:10.925: E/AndroidRuntime(4520): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680) 07-23 05:01:10.925: E/AndroidRuntime(4520): android.app で.ActivityThread.access$1500(ActivityThread.java:117) 07-23 05:01:10.925: E/AndroidRuntime(4520): android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 07-23 05: 01:10.925: E/AndroidRuntime(4520): android.os.Handler.dispatchMessage(Handler.java:99) 07-23 05:01:10.925: E/AndroidRuntime(4520): android.os.Looper.loop(Looper.java:130) 07-23 05:01:10.925: E/AndroidRuntime(4520): at android.app.ActivityThread.main(ActivityThread.java:3703) 07-23 05:01:10.925: E/AndroidRuntime(4520): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) 07-23 05:01 で:10.925: E/AndroidRuntime(4520): java.lang.reflect.Method.invoke(Method.java:507) 07-23 05:01:10.925: E/AndroidRuntime(4520): com.android.internal. os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 07-23 05:01:10.925: E/AndroidRuntime(4520): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 07 -23 05:01:10.925: E/AndroidRuntime(4520): dalvik.system.NativeStart.main(Native Method) 07-23 05:01:10.925: E/AndroidRuntime(4520): 原因: java.lang.NullPointerException 07-23 05:01:10.925: E/AndroidRuntime(4520): nsixty.crew.app.gallery.(gallery.java:49) 07-23 05:01:10.925: E/AndroidRuntime(4520): at java.lang.Class.newInstanceImpl(ネイティブメソッド) 07-23 05:01:10.925: E/AndroidRuntime(4520): java.lang.Class.newInstance(Class.java:1409) 07-23 05:01:10.925 : E/AndroidRuntime(4520): android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-23 05:01:10.925: E/AndroidRuntime(4520): android.app.ActivityThread.performLaunchActivity(ActivityThread. java:1578) 07-23 05:01:10.925: E/AndroidRuntime(4520): ... 11 もっと見るjava.lang.Class.newInstance(Class.java:1409) 07-23 05:01:10.925: E/AndroidRuntime(4520): android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-23 05 :01:10.925: E/AndroidRuntime(4520): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1578) 07-23 05:01:10.925: E/AndroidRuntime(4520): ... 11 もっと見るjava.lang.Class.newInstance(Class.java:1409) 07-23 05:01:10.925: E/AndroidRuntime(4520): android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-23 05 :01:10.925: E/AndroidRuntime(4520): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1578) 07-23 05:01:10.925: E/AndroidRuntime(4520): ... 11 もっと見る

public class gallery extends ListActivity {

private List<String> item = null;

private List<String> path = null;

private String root = "sdcard/Crews/";

private TextView myPath;
VideoView videoView;

String[] itemArr;

String[] itemArr2 = item.toArray(new String[item.size()]);
ListView list;

File folder = new File("sdcard/Crews/Videos/");

MyThumbnaildapter fileList;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.gallery);
    myPath = (TextView) findViewById(R.id.path);

    getDir(root);

    videoView = (VideoView) this.findViewById(R.id.videoView);

}

private void getDir(String dirPath)

{

    myPath.setText("Location: " + dirPath);

    item = new ArrayList<String>();

    path = new ArrayList<String>();

    File f = new File(dirPath);

    File[] files = f.listFiles();

    if (!dirPath.equals(root))

    {

        item.add(root);

        path.add(root);

        path.add(f.getParent());

    }

    for (int i = 0; i < files.length; i++)

    {

        File file = files[i];

        path.add(file.getPath());

        if (file.isDirectory()) {

            item.add(file.getName() + "/");
        }

        else {

            item.add(file.getName());
        }

    }

    fileList = new MyThumbnaildapter(this, R.layout.row, itemArr2);
    setListAdapter(fileList);
    list = (ListView) findViewById(android.R.id.list);

    list.setAdapter(fileList);
    registerForContextMenu(list);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    final File file = new File(path.get(position));

    if (file.isDirectory())

    {

        if (file.canRead()) {

            getDir(path.get(position));
            // imageThumbnail.setImageBitmap(bmThumbnail);
        }

        else

        {

            new AlertDialog.Builder(this)

            .setIcon(R.drawable.icon)

            .setTitle("[" + file.getName() + "] folder can't be read!")

            .setPositiveButton("OK",

            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    // TODO Auto-generated method stub

                }

            }).show();

        }

    }

    else

    {

        new AlertDialog.Builder(this)

        // .setIcon(R.drawable.icon)
        // .setView(getCurrentFocus())
                .setTitle("[" + file.getName() + "]")

                .setPositiveButton("OK",

                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (file.getPath().contains(".3gp")) {

                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_VIEW);

                            intent.setDataAndType(
                                    Uri.fromFile(new File(file.getPath())),
                                    "video/*");

                            startActivity(intent);

                        } else if (file.getPath().contains(".jpg")) {
                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_VIEW);

                            intent.setDataAndType(
                                    Uri.fromFile(new File(file.getPath())),
                                    "image/*");

                            startActivity(intent);
                        } else {
                            Toast displayError = Toast.makeText(
                                    gallery.this, "unsupported media type",
                                    Toast.LENGTH_SHORT);
                            displayError.show();
                        }

                    }

                }).show();
        // });
    }

}

}

public class MyThumbnaildapter extends ArrayAdapter<String> {

    public MyThumbnaildapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        View row = convertView;
        if (row == null) {
            LayoutInflater inflater = getLayoutInflater();
            row = inflater.inflate(R.layout.row, parent, false);
        }



        ImageView imageThumbnail = (ImageView) row
                .findViewById(R.id.Thumbnail);


        Bitmap bmThumbnail;
        bmThumbnail = ThumbnailUtils.createVideoThumbnail(
                itemArr2[position], Thumbnails.MICRO_KIND);
        imageThumbnail.setImageBitmap(bmThumbnail);

        return row;
    }

}
4

1 に答える 1

0

盲目的に仮定、

fileList = new MyThumbnaildapter(this, R.layout.row, itemArr2);

itemArr2はnullです。これは、アイテム配列を埋める前にグローバルに開始しようとしているためです。

String[] itemArr2 = item.toArray(new String[item.size()]);

解決策(可能性があります):

文字列配列String[] itemArr2 = item.toArray(new String[item.size()]); を埋めた後に行を入れ、item

だからここにあるはずです、

String[] itemArr2 = item.toArray(new String[item.size()]);
fileList = new MyThumbnaildapter(this, R.layout.row, itemArr2);
setListAdapter(fileList);

また、これらの2行を削除します。

list = (ListView) findViewById(android.R.id.list);
list.setAdapter(fileList);

アプリケーションコードをデバッグし、問題を見つけます。

于 2012-07-23T09:09:33.137 に答える