qianzhi008 2011-05-10 11:28
浏览 458
已采纳

Unable to start activity componentInfo

各位帮忙看一下,新手,急。。。。
启动程序时抛出这样的异常Unable to start activity ComponentInfo{com.kevin.test/com.kevin.test.Ex_07}:java.lang.NullPointerException
代码如下:
[code="java"]
public class Ex_07 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
Gallery gallery = (Gallery)findViewById(R.id.mygallery);
gallery.setAdapter(new ImageAdapter(this,getSD()));
}

private List getSD(){
List it = new ArrayList();
File file = new File("/sdcrad/photo/");
File[] files = file.listFiles();

    for(int i = 0 ; i < files.length; i++){
        File f = files[i];
        if(getImageFile(f.getPath()))
            it.add(f.getPath());
    }
    return it;
}   
private boolean getImageFile(String fname){
    boolean re;
    String end = fname.substring(fname.lastIndexOf(".")+1,fname.length()).toLowerCase();
    if(end.equals("jpg")||end.equals("gif")||end.equals("png")||end.equals("jpeg")||end.equals("bmp")){
        re = true;
    }else{
        re = false;
    }
    return re;
}

}
[/code]
[code="java"]
package com.kevin.test.adapter;

import java.util.List;

import com.kevin.test.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
private int mGalleryItemBackground;
private Context mContext;
private List list;

public ImageAdapter(Context c,List<String> list){
    mContext = c;
    this.list = list;
    // get the properties defined in attrs.xml
    TypedArray typedArray = mContext.obtainStyledAttributes(R.styleable.Gallery);
    // get Gallery's id
    mGalleryItemBackground = typedArray.getResourceId(R.styleable.Gallery_android_galleryItemBackground, 0);
    typedArray.recycle();
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return list.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ImageView i = new ImageView(mContext);
    Bitmap bm = BitmapFactory.decodeFile(list.get(position).toString());
    i.setImageBitmap(bm);
    i.setScaleType(ImageView.ScaleType.FIT_XY);
    i.setLayoutParams(new Gallery.LayoutParams(136, 88));
    i.setBackgroundResource(mGalleryItemBackground);
    return i;
}

}
[/code]
androidMainifest.xml文件
[code="java"]
<?xml version="1.0" encoding="utf-8"?>
package="com.kevin.test"
android:versionCode="1"
android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Ex_07"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>


[/code]

  • 写回答

2条回答

  • iteye_8576 2011-05-10 14:50
    关注

    是不是 路径"/sdcrad/photo/" 没有文件?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)