java.lang.NullPointerException

k144521 2009-12-19 11:12:11
为什么我的APPLET在Java中运行正常,但在JSP中调用就报错呢
错误信息:
java.lang.NullPointerException
at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
异常:java.lang.NullPointerException

APPLET源码很长 在这里就不传上来了 就是JFREECHART曲线 与ORACLE 连接数据 曲线在APPLET中正常运行
...全文
97 10 打赏 收藏 举报
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazylaa 2009-12-21
  • 打赏
  • 举报
回复
一堆 Unknow source.........
检查你的浏览器是否禁用java小程序了。
检查你的applet是否需要签名才能运行。

这种情况一般都是环境问题造成的。
k144521 2009-12-20
  • 打赏
  • 举报
回复
最上面呢
whut_lcy 2009-12-20
  • 打赏
  • 举报
回复
异常打印业贴出来啊
k144521 2009-12-20
  • 打赏
  • 举报
回复
大家看这段
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.21.193:1521:orcl", "biaoguanli", "aaa");
if(y1==y|m1==m|dm1==dm) {
sql = con.prepareStatement("select * from system.d1_"+y+mo+dm+" where DAW >= ? and DAW <= ? ");// 大于左时间 小于右时间
}
else {
sql = con.prepareStatement("select * from system.d1_"+y1+mo1+dm1+" where DAW >= ? and DAW <= ? UNION select * from system.d1_"+y+mo+dm+" where DAW >= ? and DAW <= ?");
}
sql.setString(1, ltime);
sql.setString(2, rtime);
rs = sql.executeQuery();
if(rs==null){
try {
System.out.println("sjdfnf");//throw new Exception("数据库操作失败。");
} catch (NullPointerException e) {
e.printStackTrace();
}
}
while (rs.next()) {
int[] y0 = new int[]{rs.getInt(2)};
int[] l0 = new int[]{rs.getInt(3)};
String sss=rs.getString("DAW");
int x=Integer.parseInt(sss.substring(0,4));
int ye=Integer.parseInt(sss.substring(5,7));
int z=Integer.parseInt(sss.substring(8,10));
int a=Integer.parseInt(sss.substring(11,13));
int b=Integer.parseInt(sss.substring(14,16));
for(int i = 0; i < y0.length; i++){
ca.addOrUpdate(new Minute(b,new Hour(a,new Day(z,ye,x))),y0[i]);
yali.addOrUpdate(new Minute(b,new Hour(a,new Day(z,ye,x))),l0[i]);

}
}

rs.close();
sql.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(ca);
dataset.addSeries(yali);
dataset.setDomainIsPointsInTime(true);
k144521 2009-12-20
  • 打赏
  • 举报
回复
我实在没有办法了 在Eclipse中根本就不报错误 rs不为空的
k144521 2009-12-20
  • 打赏
  • 举报
回复
import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import javax.swing.JApplet;
import javax.swing.JButton;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYDataset;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.Hour;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class MyJfreechart1 extends JApplet implements ActionListener,ItemListener{
PreparedStatement sql,sql1;
Connection con,con1;
ResultSet rs ,rs1;
static JButton jbutton1,jbutton2,jbutton3,jbutton4,jbutton5;
Choice timerss = new Choice();
public int time1 = 10 ;
public int time0 =0;
int hour1 = 0;
int hour0 = 0;

Calendar calendar2 = Calendar.getInstance();
Calendar calendar1 = Calendar.getInstance();
TimeSeries ca = new TimeSeries("流量",Minute.class);//时间的最小单位为分,线值名是“平均”
TimeSeries yali = new TimeSeries("压力",Minute.class);//时间的最小单位为分,线值名是“平均”

public void init() {
this.setSize(800, 600);
XYDataset xydataset = null;
try {
xydataset = createDataset();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
JFreeChart jfreechart = createChart(xydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart, false);
chartpanel.setPreferredSize(new Dimension(500, 270));
chartpanel.setMouseZoomable(true, false);
setContentPane(chartpanel);
FlowLayout f = new FlowLayout();
this.setLayout(f);
jbutton1 = new JButton("快退");
jbutton2 = new JButton("慢退");
jbutton3 = new JButton("现在");
jbutton4 = new JButton("慢进");
jbutton5 = new JButton("快进");

jbutton1.addActionListener(this);
jbutton2.addActionListener(this);
jbutton3.addActionListener(this);
jbutton4.addActionListener(this);
jbutton5.addActionListener(this);

this.add(jbutton1,BorderLayout.SOUTH);
this.add(jbutton2,BorderLayout.SOUTH);
this.add(jbutton3,BorderLayout.SOUTH);
this.add(jbutton4,BorderLayout.SOUTH);
this.add(jbutton5,BorderLayout.SOUTH);
this.add(timerss);
timerss.add("30分钟线");
timerss.add("1小时线");
timerss.add("6小时线");
timerss.addItemListener(this);
}

private static JFreeChart createChart(XYDataset xydataset){
//曲线图标题
String title = " ";
// 曲线图X轴提示
String domain = "走势";
// 曲线图Y轴提示
String range = "流量";
// 曲线图自标题
String subtitleStr = " ";
// 时间曲线元素
JFreeChart chart = ChartFactory.createTimeSeriesChart(title, domain,range,xydataset, true, true,true);
// 标题
TextTitle subtitle = new TextTitle(subtitleStr, new Font("黑体",Font.BOLD, 12));
//子标题
chart.addSubtitle(subtitle);//子标题文字
chart.setTitle(new TextTitle(title, new Font("黑体", Font.PLAIN, 15)));//标题文字
//设置背景颜色
//chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000,Color.blue));
//设置底部文字
chart.getLegend().setItemFont(new Font("黑体",Font.PLAIN,12));//底部文字
//设置XY轴的文字
XYPlot plot=chart.getXYPlot();//获得曲线图的绘制结构对象
ValueAxis domainAxis=plot.getDomainAxis();//获得x轴区域对象
ValueAxis rangeAxis=plot.getRangeAxis();//获得y轴区域对象
domainAxis.setLabelFont(new Font("黑体",Font.PLAIN,12));//设置x轴标题文字
domainAxis.setTickLabelFont(new Font("黑体",Font.PLAIN,12));//设置x轴坐标上的文字
rangeAxis.setLabelFont(new Font("黑体",Font.PLAIN,12));//设置y轴标题文字
rangeAxis.setTickLabelFont(new Font("黑体",Font.PLAIN,12));//设置y轴坐标上的文字
domainAxis.setVerticalTickLabels(true);//x轴文字垂直显示
plot.setNoDataMessage("没有数据");
return chart;
}

private XYDataset createDataset() throws ClassNotFoundException, SQLException ,NullPointerException{
Calendar calendar2 = Calendar.getInstance();
Calendar calendar1 = Calendar.getInstance();
int y,m,d,h,mi,s,mi1,h1;
String mo,dm,hh,mn,ss,mn1,hh1;
String rtime = null;
String ltime = null;
calendar1.add(Calendar.MINUTE,-time1);//左时间
calendar2.add(Calendar.MINUTE,-time0);//右时间
calendar1.add(Calendar.HOUR_OF_DAY,-hour1);//左时间
calendar2.add(Calendar.HOUR_OF_DAY,-hour0+1);//右时间
y=calendar2.get(Calendar.YEAR);
m=calendar2.get(Calendar.MONTH)+ 1;
d=calendar2.get(Calendar.DATE);
h=calendar2.get(Calendar.HOUR_OF_DAY);
mi=calendar2.get(Calendar.MINUTE);
s=calendar2.get(Calendar.SECOND);
h1=calendar1.get(Calendar.HOUR_OF_DAY);
mi1=calendar1.get(Calendar.MINUTE);
mo = MyJfreechart1.intToString(m);
mo = MyJfreechart1.trimString(mo,1);
dm = MyJfreechart1.intToString(d);
dm = MyJfreechart1.trimString(dm,1);
hh = MyJfreechart1.intToString(h);
hh = MyJfreechart1.trimString(hh,1);
hh1 = MyJfreechart1.intToString(h1);
hh1 = MyJfreechart1.trimString(hh1,1);
mn = MyJfreechart1.intToString(mi);
mn = MyJfreechart1.trimString(mn,1);
mn1 = MyJfreechart1.intToString(mi1);
mn1 = MyJfreechart1.trimString(mn1,1);
ss = MyJfreechart1.intToString(s);
ss = MyJfreechart1.trimString(ss,1);

ltime = y+"-"+mo+"-"+dm+" "+hh1+":"+mn1+":"+ss;//左时间
rtime = y+"-"+mo+"-"+dm+" "+hh+":"+mn+":"+ss;//右时间
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println(ltime+" "+rtime);
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.21.193:1521:orcl", "biaoguanli", "aaa");
sql = con.prepareStatement("select * from system.d1_20091219 ");// 大于左时间 小于右时间where DAW >= ? and DAW <= ?
// sql.setString(1, ltime);
// sql.setString(2, rtime);
rs = sql.executeQuery();
if(rs!=null){
while (rs.next()) {
int[] y0 = new int[]{rs.getInt(2)};
int[] l0 = new int[]{rs.getInt(3)};
String sss=rs.getString("DAW");
int x=Integer.parseInt(sss.substring(0,4));
int ye=Integer.parseInt(sss.substring(5,7));
int z=Integer.parseInt(sss.substring(8,10));
int a=Integer.parseInt(sss.substring(11,13));
int b=Integer.parseInt(sss.substring(14,16));
for(int i = 0; i < y0.length; i++){
ca.addOrUpdate(new Minute(b,new Hour(a,new Day(z,ye,x))),y0[i]);
yali.addOrUpdate(new Minute(b,new Hour(a,new Day(z,ye,x))),l0[i]);
//System.out.println(rtime+" "+ltime+" "+x+" "+ye+" "+z+" "+a+" "+b+" "+y0[i]+" "+sss);
}
}
}
con.close();
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(ca);
dataset.addSeries(yali);
dataset.setDomainIsPointsInTime(true);
return dataset;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==jbutton1){
hour0 += 1;
hour1 += 1;
time1=time0=0;
}
else if(e.getSource()==jbutton2){
time1 += 10;
time0 += 10;
hour0 =hour1= 0;
}
else if(e.getSource()==jbutton3){
time1 = 10;
time0 = 0;
hour0 =hour1= 0;
}
else if(e.getSource()==jbutton4){
time1 += -10;
time0 += -10;
hour0 =hour1= 0;
}
else if(e.getSource()==jbutton5){
hour0 += -1;
hour1 += -1;
time1=time0=0;
}
try {
ca.clear();
yali.clear();
XYDataset xydataset = createDataset();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}

public static String intToString(int value)
{
Integer integer = new Integer(value);
return integer.toString();
}
public static String trimString(String str,int n) {
String sTemp = str;
int nl = str.length();
if(nl > n) {}
else sTemp = "0" + str;
return sTemp;
}
public void itemStateChanged(ItemEvent e) {
if (timerss.getSelectedIndex() == 0) {
time1 =30;
time0 =0;
}
if (timerss.getSelectedIndex() == 1) {
time1 =60;
time0 =0;
}
if (timerss.getSelectedIndex() == 2) {
time1 =360;
time0 =0;
}
try {
ca.clear();
yali.clear();
XYDataset xydataset = createDataset();

} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
formatchenzhiguo 2009-12-20
  • 打赏
  • 举报
回复
你光发个错误提示,一百个人来了也只能告诉你是空指针异常,因为你只给了错误提示你用断点走一下看看在什么地方出了毛病。
k144521 2009-12-19
  • 打赏
  • 举报
回复
我知道是这个意思 不过我在Eclipse中运行时正常的 有数据的
crazysox 2009-12-19
  • 打赏
  • 举报
回复
空针
k144521 2009-12-19
  • 打赏
  • 举报
回复
为什么没有人关注呢?
大家帮帮小弟吧 数据库根本就不是空的 在ECLIPSE能成功运行出曲线 为什么JSP中就报错
发帖
Java

4.9w+

社区成员

Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
帖子事件
创建了帖子
2009-12-19 11:12
社区公告
暂无公告