07-23 05:01:10.925: E/AndroidRuntime(4520): 致命异常: main 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): 在android.app.ActivityThread.main(ActivityThread.java:3703) 07-23 05:01:10.925: E/AndroidRuntime(4520): 在 java.lang.reflect.Method.invokeNative(Native Method) 07-23 05:01 :10.925: E/AndroidRuntime(4520): at java.lang.reflect.Method.invoke(Method.java:507) 07-23 05:01:10.925: E/AndroidRuntime(4520): at com.android.internal。 os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 07-23 05:01:10.925: E/AndroidRuntime(4520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 07 -23 05:01:10.925: E/AndroidRuntime(4520): at dalvik.system.NativeStart.main(Native Method) 07-23 05:01:10.925: E/AndroidRuntime(4520): Caused by: 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): 在java.lang.Class.newInstanceImpl(Native Method) 07-23 05:01:10.925: E/AndroidRuntime(4520): at 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;
}
}