Javaコンパイルエラー:No enclosing instance of type AAis accessible

1265 ワード

問題の説明:
Javaコンパイルエラー「No enclosing instance of type CreateImageData is accessible.Must qualify the allocation with an enclosing instance of type CreateImageData(e.g.x.new A()where x is an instance of CreateImageData)」
コードは次のとおりです.
public class CreateImageData
{
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		...
		createImage(targetFolder, batchType, currentDay, batchFrom + i, batchSum, imageQuarryName, bpuID, tableNos);
		...
	}

	private static List<AppInfo> createImage(String targetFolder, String batchType, 
			String currentDay, int batchNum, int batchSum, String imageQuarryName, String bpuID, String[] tableNos)
	{
			......
			AppInfo appInfo = new AppInfo();

			......
		}
		return returnValue;
	}

	private class AppInfo
	{
		......
	}
}
 
 
 
問題の原因:
内部クラスインスタンスは外部クラスインスタンスに依存する.外部クラスのstaticメソッドはnew外部クラスインスタンスを必要とせずに直接呼び出すことができる.したがって,外部クラスのstaticメソッドで内部クラスを直接インスタンス化すると,このコンパイルエラーが発生する.
 
解決方法:
1、staticメソッドを非staticメソッドに変更します.
2、new内部クラスのオブジェクトを修正する方法:AppInfo appInfo=new CreateImageData().new AppInfo();