当前位置: 技术问答>java相关
紧急求救,请问为何一直出错?ShowContent.java:7: 缺少返回语句 },这是为什么?多谢了!
来源: 互联网 发布时间:2015-01-07
本文导语: 我创建了一个最终类ShowContent.java,程序如下: package pagination; import java.sql.*; public final class ShowContent { public static String[] table() { try { String table[] = new String[2]; table[0]=""; table[1]=""; ...
我创建了一个最终类ShowContent.java,程序如下:
package pagination;
import java.sql.*;
public final class ShowContent
{
public static String[] table()
{
try
{
String table[] = new String[2];
table[0]="";
table[1]="";
return table;
}catch(Exception e){System.out.println(e);}
}
public static String[] th(int num,int maxperpage,ResultSet result)
{
try
{
String th[] = new String[num];
for(int i=0;ijavac ShowContent.java
ShowContent.java:7: 缺少返回语句
{
^
ShowContent.java:17: 缺少返回语句
{
^
ShowContent.java:30: 缺少返回语句
{
^
3 个错误
请问这是为什么?多谢了!
package pagination;
import java.sql.*;
public final class ShowContent
{
public static String[] table()
{
try
{
String table[] = new String[2];
table[0]="";
table[1]="";
return table;
}catch(Exception e){System.out.println(e);}
}
public static String[] th(int num,int maxperpage,ResultSet result)
{
try
{
String th[] = new String[num];
for(int i=0;ijavac ShowContent.java
ShowContent.java:7: 缺少返回语句
{
^
ShowContent.java:17: 缺少返回语句
{
^
ShowContent.java:30: 缺少返回语句
{
^
3 个错误
请问这是为什么?多谢了!
|
同意楼上的看法!
你也可以这样,只写一个返回语句:
public static String[] table()
{
String table[] = null;
try
{
table[] = new String[2];
table[0]="";
table[1]="";
}
catch(Exception e)
{
System.out.println(e);
}
return table;
}
你也可以这样,只写一个返回语句:
public static String[] table()
{
String table[] = null;
try
{
table[] = new String[2];
table[0]="";
table[1]="";
}
catch(Exception e)
{
System.out.println(e);
}
return table;
}
|
改为
public static String[] table()
{
String table[] = new String[2];
try
{
table[0]="";
table[1]="";
return table;
}
catch(Exception e)
{
System.out.println(e);
return table;
}
}
即可
public static String[] table()
{
String table[] = new String[2];
try
{
table[0]="";
table[1]="";
return table;
}
catch(Exception e)
{
System.out.println(e);
return table;
}
}
即可
|
在catch(Exception e){}
也要 return 的
也要 return 的
|
有可能在try中出错,就会没有返回值,最好是在try的外面,或finally中返回
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。