You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FileNameExtensionFilter多参数构造函数Lint报错未定义,如何修复?

Fixing the FileNameExtensionFilter Constructor Error

Let's break down what's going wrong here and how to fix it quickly.

First, let's look at your problematic code:

FileNameExtensionFilter filter = new FileNameExtensionFilter("*.Images", "jpg", "png", "gif", "jpeg");

The lint error The constructor FileNameExtensionFilter(String, String, String, String, String) is undefined pops up because you're misusing the constructor of javax.swing.filechooser.FileNameExtensionFilter. Here's what you need to adjust:

  • Fix the first parameter: The first argument isn't a wildcard filter string (like *.Images), it's a human-readable description of the file type. For example, use "Image Files" instead of "*.Images".
  • Confirm the constructor logic: The class uses a varargs parameter for extensions, so passing multiple extension strings is totally allowed—your issue isn't the number of extensions, it's the invalid first parameter.

Here's the corrected code:

FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "jpg", "png", "gif", "jpeg");

Why does this work?

The official constructor signature for FileNameExtensionFilter is:

public FileNameExtensionFilter(String description, String... extensions)
  • The description is what users see in the file chooser dropdown (e.g., "Image Files" is much clearer than a cryptic wildcard string).
  • The extensions are the file suffixes to filter, without the leading dot—the class handles adding the dot internally when applying the filter.

If you still see the error after this fix, double-check that you've imported the correct class:

import javax.swing.filechooser.FileNameExtensionFilter;

Avoid importing any other custom or third-party FileNameExtensionFilter classes that might have different constructor signatures.

内容的提问来源于stack exchange,提问作者Amant Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:37:31