GVKun编程网logo

Access restriction: The type XXX is not accessi...

3

在本文中,我们将为您详细介绍Accessrestriction:ThetypeXXXisnotaccessi...的相关知识,此外,我们还会提供一些关于Accessrestrictiononclass

在本文中,我们将为您详细介绍Access restriction: The type XXX is not accessi...的相关知识,此外,我们还会提供一些关于Access restriction on class due to restriction ...、Access restriction 错误、Access restriction: is not accessible、Access restriction: The constructor SunJCE() is not accessib的有用信息。

本文目录一览:

Access restriction: The type XXX is not accessi...

Access restriction: The type XXX is not accessi...



- Access restriction: The type IInboundMessageNotification is not accessible due to restriction on required library C:\Program Files\Java\jdk\jre\lib\ext
  \jdsmsserver-3.4.jar


google了一下 下面是解决方法:

Eclipse 默认把这些受访问限制的API设成了ERROR。只要把Windows-Preferences-Java-Complicer- Errors/Warnings里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过。

 

不过这个不好,如果你的jre目录里面有你项目需要引用的jar包 ,而你又引用了外部jar包,也就是说引用了两次,

如果你想让起作用的是手动引用的外部jar包 这个时候需要把 "Referenced Library" 调整到 "JRE System Library"上面



引用的顺序是从上到下

改变顺序前的效果:

build path

最后效果

OK   一切正常...

Access restriction on class due to restriction ...

Access restriction on class due to restriction ...

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library.

This works because you have multiple classes in different jar files. Removing and re-adding the jre lib will make the right classes be first. If you want a fundamental solution make sure you exclude the jar files with the same classes.

Access restriction 错误

Access restriction 错误

原因:
Eclipse 默认把这些受访问限制的API设成了ERROR。
解决办法:
只要把Windows-Preferences-Java-Complicer- Errors/Warnings里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过。


Access restriction: is not accessible

Access restriction: is not accessible

最近在做关于图片操作的问题,但是发现在eclipse中,对于某些rt.jar里面的方法访问的时候,会出现错误提示: Access restriction: XXXXXXXXX  is not accessible due to restriction on required library XXXXX
本例的错误信息为 :  程序包com.sun.image.codec.jpeg不存在
一下所引入的包也有可能会发生问题: 例如  import sun.misc.BASE64Decoder;  import com.sun.image.codec.jpeg.JPEGCodec;
会发现有一些解决方案:

解决办法一:
1. Open project properties.
2. Select Java Build Path node.
3. Select Libraries tab.
4. Remove JRE System Library 一次
5. 再次 Add Library JRE System Library

解决方案二:
Window-->Preferences-->Java-->Compiler-->Error/Warnings-->Deprecated and Restricted API  改为 warning

其实如果是操作某些非公开的JDK API的话,会出现这些问题,可以使用上述的解决方案,但是建议使用其他的方案代替,例如下例所给出的解决方案,用scaleImage2 代替 scaleImage 不使用受保护的方法


package com.zy.common.util;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;


public class ImagesUtil {

	/**
     * 缩略图片
     * @param oldpath 原图片
     * @param newpath 新生成的图片存放地址
     * @param wdith   缩略后的宽
     * @param height  缩略后的高
     */
    public static void scaleImage(String oldpath, String newpath, int wdith, int height) {
    	// 获取老的图片
    	File oldimg = new File(oldpath);
		try {
			BufferedImage bi = ImageIO.read(oldimg);
			Image Itemp = bi.getScaledInstance(wdith, height, BufferedImage.SCALE_SMOOTH);
			BufferedImage thumbnail = new BufferedImage(wdith, height, BufferedImage.TYPE_INT_RGB);
			thumbnail.getGraphics().drawImage(Itemp, 0, 0, null);
			// 缩略后的图片路径
			File newimg = new File(newpath);
			//FileOutputStream out = new FileOutputStream(newimg);
			// 绘图
			//JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			//JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbnail);
			//param.setQuality(1.0f, false);
			//encoder.encode(thumbnail);
			//out.close();
			String formatName = newpath.substring(newpath.lastIndexOf(".") + 1); 
			ImageIO.write(thumbnail,  formatName , new File(newpath) );
			bi.flush();
			bi = null;
		} catch (IOException e) {
			System.out.println(e.getStackTrace());
		}
    }
    
    /**
     * 缩略图片
     * @param oldpath 原图片
     * @param newpath 新生成的图片存放地址
     * @param wdith   缩略后的宽
     * @param height  缩略后的高
     */
    public static void scaleImage2(String oldpath, String newpath, int wdith, int height) {
    	// 获取老的图片
    	File oldimg = new File(oldpath);
		try {
			BufferedImage bi = ImageIO.read(oldimg);
			Image Itemp = bi.getScaledInstance(wdith, height, BufferedImage.SCALE_SMOOTH);
			BufferedImage thumbnail = new BufferedImage(wdith, height, BufferedImage.TYPE_INT_RGB);
			thumbnail.getGraphics().drawImage(Itemp, 0, 0, null);
			// 缩略后的图片路径
			File newimg = new File(newpath);
			FileOutputStream out = new FileOutputStream(newimg);
			// 绘图
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbnail);
			param.setQuality(1.0f, false);
			encoder.encode(thumbnail);
			out.close();
			bi.flush();
			bi = null;
		} catch (IOException e) {
			System.out.println(e.getStackTrace());
		}
    }

}



Access restriction: The constructor SunJCE() is not accessib

Access restriction: The constructor SunJCE() is not accessib

问题现象: Access restriction: The constructor SunJCE() is not accessible due to restriction on required library 原因分析: 大致意识是依赖库SunJCE() 构造函数被限制访问; 解决思路: 方案一: Window - Preferences - Java - Compiler - Errors/War

问题现象:

        Access restriction: The constructor SunJCE() is not accessible due to restriction on required library 

原因分析:

        大致意识是依赖库 SunJCE() 构造函数被限制访问;

解决思路:

方案一:Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rules) -> Warnings


Access restriction: The constructor SunJCE() is not accessib未完待续....

今天关于Access restriction: The type XXX is not accessi...的分享就到这里,希望大家有所收获,若想了解更多关于Access restriction on class due to restriction ...、Access restriction 错误、Access restriction: is not accessible、Access restriction: The constructor SunJCE() is not accessib等相关知识,可以在本站进行查询。

本文标签: