Long a1=new Long(First);First为String型,这句错在哪里?

xlt771111 2001-11-14 02:51:42
Long a1=new Long(First);First为String型,这句错在哪里?
...全文
168 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlt771111 2001-11-15
  • 打赏
  • 举报
回复
好了,谢谢
Kosame 2001-11-15
  • 打赏
  • 举报
回复
和str一样,在开始的时候把First初始化一下试试
String First = "";
xlt771111 2001-11-15
  • 打赏
  • 举报
回复
first是有值的,str也是有值的,str="20:30:11" first=2 ,这是一个投票程序
Kosame 2001-11-15
  • 打赏
  • 举报
回复
你到底想做些什么?
如果是想做Long型的转换,前面的已经说了呀
首先First应该是String型的数字吧,不为null
然后调Long al = new Long(Long.parseLong(First));

如果你想看First的值
看你上面的程序,不一定会走到(String First=str.substring(0,first);)这个case吧
那First没初始化呀,如何显示呢?
xlt771111 2001-11-15
  • 打赏
  • 举报
回复
Kosame(新鬼影):不行啊,我想First是String型
Kosame 2001-11-15
  • 打赏
  • 举报
回复
System.out.println
xlt771111 2001-11-15
  • 打赏
  • 举报
回复
如何显示First,Next,Last的值啊,怎么用out.println(First)不行啊,不好意思,太菜了
cannavaro 2001-11-14
  • 打赏
  • 举报
回复
Long a1=new Long(First).longValue();
cannavaro 2001-11-14
  • 打赏
  • 举报
回复
Long a1=new Long(First).longValue();
cannavaro 2001-11-14
  • 打赏
  • 举报
回复
Long a1=new Long(First).longValue();
ycats 2001-11-14
  • 打赏
  • 举报
回复
只要你的First,Next,Last保证是数字就可以!!否则就运行出错NumberFormatException!!!
xlt771111 2001-11-14
  • 打赏
  • 举报
回复
源码如下,请各位细看,谢谢

String resultsDir="D:";
out.println(resultsDir+System.getProperty("file.separator")+"EE.txt");
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty("file.separator")+"EE.txt");

String str="";
int c;
while ((c=tfile.read())!=-1)
{
str=str+(char)c;
}
int first=str.indexOf(":");
out.println("first="+first);
int last=str.lastIndexOf(":");
out.println("last="+last);
int lenth=str.length();
out.println("length="+lenth);
if(first>0&&first<=str.length())
{
String First=str.substring(0,first);
}
out.println("First="+first);

if(last>0&&last<=str.length())
{
String Next=str.substring(first+1,last);
}
if(lenth>0&&lenth<=str.length())
{
String Last=str.substring(last+1,lenth);
}
//String First=str.substring(0,first);
//String Next=str.Substring(first+1,last);
//String Last=str.Substring(last+1,lenth);
tfile.close();
//int a1;
//a1 = Integer.parseInt(First);
//out.println((Long) a1);
Long a1=new Long(First);
Long a2=new Long(Next);
Long a3=new Long(Last);

long b1=a1.longValue();
long b2=a2.longValue();
long b3=a3.longValue();

long total=b1+b2+b3;

float h0=100*((float)b1/(float)total);
float h1=100*((float)b2/(float)total);
float h2=100*((float)b3/(float)total);

out.println("Select1<img src=dot.gif width="+h0+"height=15"+b1+"<br>");
out.println("Select2<img src=dot.gif width="+h1+"height=15"+b2+"<br>");
out.println("Select3<img src=dot.gif width="+h2+"height=15"+b3+"<br>");
out.println("Total:"+total);*/
xlt771111 2001-11-14
  • 打赏
  • 举报
回复
源码如下,请各位细看,谢谢

String resultsDir="D:";
out.println(resultsDir+System.getProperty("file.separator")+"EE.txt");
FileInputStream tfile=new FileInputStream(resultsDir+System.getProperty("file.separator")+"EE.txt");

String str="";
int c;
while ((c=tfile.read())!=-1)
{
str=str+(char)c;
}
int first=str.indexOf(":");
out.println("first="+first);
int last=str.lastIndexOf(":");
out.println("last="+last);
int lenth=str.length();
out.println("length="+lenth);
if(first>0&&first<=str.length())
{
String First=str.substring(0,first);
}
out.println("First="+first);

if(last>0&&last<=str.length())
{
String Next=str.substring(first+1,last);
}
if(lenth>0&&lenth<=str.length())
{
String Last=str.substring(last+1,lenth);
}
//String First=str.substring(0,first);
//String Next=str.Substring(first+1,last);
//String Last=str.Substring(last+1,lenth);
tfile.close();
//int a1;
//a1 = Integer.parseInt(First);
//out.println((Long) a1);
Long a1=new Long(First);
Long a2=new Long(Next);
Long a3=new Long(Last);

long b1=a1.longValue();
long b2=a2.longValue();
long b3=a3.longValue();

long total=b1+b2+b3;

float h0=100*((float)b1/(float)total);
float h1=100*((float)b2/(float)total);
float h2=100*((float)b3/(float)total);

out.println("Select1<img src=dot.gif width="+h0+"height=15"+b1+"<br>");
out.println("Select2<img src=dot.gif width="+h1+"height=15"+b2+"<br>");
out.println("Select3<img src=dot.gif width="+h2+"height=15"+b3+"<br>");
out.println("Total:"+total);*/
firetree 2001-11-14
  • 打赏
  • 举报
回复
String不能直接造成Long型
下面的代码可以实现你想的操作
try{
Long al = new Long(Long.parseLong(First));
}catch(NumberFormatException nfe){
}
xlt771111 2001-11-14
  • 打赏
  • 举报
回复
chinaillboy(浪漫不起来):我执行了一下,这一句
a1 = Integer.parseInt(First);出错
ycats 2001-11-14
  • 打赏
  • 举报
回复
这一句本身没有错,但它可能产生错误。如果First的值不恰当的话。
xlt771111 2001-11-14
  • 打赏
  • 举报
回复
为什么没人理
chinaillboy 2001-11-14
  • 打赏
  • 举报
回复
a1 = Integer.parseInt(First);
out.println((Long) a1);
xlt771111 2001-11-14
  • 打赏
  • 举报
回复
??????

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧