gpt4 book ai didi

java - File.delete() 被忽略

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:12:04 24 4
gpt4 key购买 nike

<分区>

我目前遇到一些错误,它给了我空指针。所以这是代码。

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.catalog_view);
name = (TextView) findViewById(R.id.textView1);
buttonDel = (Button) findViewById(R.id.buttonDel);
buttonBack = (ImageButton) findViewById(R.id.imageButton1);


mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));

Bundle bundle = getIntent().getExtras();
mPath = bundle.getString("path");

thelabels = new labels(mPath);
thelabels.Read();

count = 0;
int max = thelabels.max();
for (int i = 0; i <= max; i++)
{
if (thelabels.get(i) != "") {
count++;
}
}

bmlist = new Bitmap[count];
namelist = new String[count];
count = 0;
for (int i = 0; i < max; i++){
if (thelabels.get(i) != "");{
File root = new File(mPath);
final String fname = thelabels.get(i);
FilenameFilter pngFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().startsWith(fname.toLowerCase() + "-");
}
};

File[] imageFiles = root.listFiles(pngFilter);
if (imageFiles.length > 0){
InputStream is;
try{
is = new FileInputStream(imageFiles[0]);

bmlist[count] = BitmapFactory.decodeStream(is);
namelist[count] = thelabels.get(i);
}
catch (FileNotFoundException e){
// TODO Auto-generated catch block
Log.e("File error", e.getMessage() + " " + e.getCause());
e.printStackTrace();
}
}

count++;
}
}
g = (Gallery) findViewById(R.id.gallery1);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);


buttonBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});

buttonDel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

File root = new File(mPath);
FilenameFilter pngFilter = new FilenameFilter() {
public boolean accept(File dir, String n) {
String s = name.getText().toString();
return n.toLowerCase().startsWith(s.toLowerCase() + "-");
}
};
File[] imageFiles = root.listFiles(pngFilter);
for (File image : imageFiles) {
image.delete();
int i;
for (i = 0; i < count; i++) {
if (namelist[i].equalsIgnoreCase(name.getText().toString())) {
Log.i("Delete operation", name.getText().toString());
int j;
for (j = i; j < count - 1; j++) {
namelist[j] = namelist[j + 1];
bmlist[j] = bmlist[j + 1];
}
count--;
refresh();
break;
}
}
}
}
});
}

错误指向这一行

if (namelist[i].equalsIgnoreCase(name.getText().toString()))

错误

 Process: com.example.syafiq.facialrecognition, PID: 29294
java.lang.NullPointerException
at com.example.syafiq.facialrecognition.ImageGallery$3.onClick(ImageGallery.java:135)
at android.view.View.performClick(View.java:4654)
at android.view.View$PerformClick.run(View.java:19438)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)

如果我的问题没有准备好,我真的很抱歉。我是 android 编程的新手。我真的希望你们能帮我解决这个错误 :( 非常感谢你们抽出宝贵的时间。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com