空或抛出异常(Null or throw exception)
public class Learner { public static void main(String[] args) { String[] dataArr = new String[4]; dataArr[1] = "Bill"; dataArr[2] = "Steve"; dataArr[3] = "Larry"; try{ for(String data : dataArr){ System.out.print(data+" "); } }catch(Exception e){ System.out.println(e.getClass()); } } }
这本书将说明这将打印:null Bill Steve Larry
这让我感到困惑,因为我认为使用null访问任何数据都会抛出NullPointerException。 在访问具有空值的数组时是否曾经抛出异常?
或者是system.out.println(),保存恩典? 你可以使用for循环访问任何空值,只要不说你在上面调用data.length()吗?
public class Learner { public static void main(String[] args) { String[] dataArr = new String[4]; dataArr[1] = "Bill"; dataArr[2] = "Steve"; dataArr[3] = "Larry"; try{ for(String data : dataArr){ System.out.print(data+" "); } }catch(Exception e){ System.out.println(e.getClass()); } } }
The book states this will print: null Bill Steve Larry
This confuses me as I thought accessing any data with null will throw a NullPointerException. Is there ever a time when an exception is thrown when accessing an array with null values?
Or is system.out.println(), the saving grace? Can you access any null value with a for loop, as long as your not say calling data.length() on it?
原文:https://stackoverflow.com/questions/32192813
最满意答案
添加新的自定义帖子类型时,您需要刷新永久链接。
转到设置 - >管理员中的永久链接,然后点击保存。
When you add a new custom post type, you need to flush your permalinks.
Go to Settings -> Permalinks in the admin and hit save.
相关问答
更多-
__()函数只是一个翻译器。 请参阅WP的函数参考 。 因此,要继续使其可翻译,请将文本域(也称为twentythirteen )更改为需要翻译的地方。 在你的情况下, mysite-core 。 这是最佳实践,以便您的插件可以以标准方式国际化。 看到这里 。 The __() function is just a translator. See WP's function reference. So, to continue making it translatable, change the text ...
-
将我的评论扩展为答案...... 问题是您正在将完整的HTML文档插入到Wordpress模板中。 除非修改模板的最外层“层”,否则HTML文档的doctype,head和body部分已经存在。 你添加的任何东西都会在body标签的某个地方结束。 每个HTML文档只能有一个标记,添加更多将导致浏览器行为不稳定。 您应该为标题部分使用
(可选), 和 -
标记的组合。 在Wordpress中,头部中的标题通常是通过Wordpress用户界面添加页面 ...
-
你可以为.entry-title类添加一个css规则 .entry-title{ position: absolute; top: -200px; text-align: center; width: 100%; left: 0; font-size: 50px; color: white; } 这是有效的规则应该适用于所有.entry标题和标题图像是在每个页面中相同的尺寸 could you add a css rule for .entry-ti ...
-
要重命名帖子类型标签,我们需要操纵全局$wp_post_types 。 请注意,帖子类型是portfolio ,标签只是虚拟文本。 add_action( 'init', 'object_label_so_16097216', 0 ); function object_label_so_16097216() { global $wp_post_types; $labels = &$wp_post_types['portfolio']->labels; // <-- adjust CPT ...
-
如何减少WordPress Twenty 17主题中的标题图片高度(How to reduce the header image height in WordPress Twenty Seventeen theme)[2021-12-23]
在Twenty 17主题的功能文件中,您可以修改标题宽度/高度,它定义为下面提到的函数。 add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true ); 对于上述功能,您还必须在css中调整高度,您还可以像下面的示例一样调整高度。 .has-header-image.twentyseventeen-front-page .custom-header, .has-header-video.twentyseventeen-front- ... -
它在这个文件中 - http://www.pantsdownrecords.com/wp-content/themes/twentyseventeen/assets/js/global.js?ver=1.0 在adjustScrollClass()函数下。 你可以使用!important在你的CSS中覆盖一个内联样式。 您应该谨慎使用该功能,但如果您需要覆盖内联样式,则此功能可用。 It's in this file - http://www.pantsdownrecords.com/wp-content/ ...
-
在wordpress主题中添加第二个自定义帖子类型时出错(error adding the second custom post type in wordpress theme)[2020-01-28]
检查functions.php文件的第83行。 你可能有一个关闭的php标记和后面的新行/空格。 在结束标记之后删除任何不必要的空格。 参考 - 如何修复PHP中的“已发送标头”错误 Check line 83 of your functions.php file. You probably have a closing php tag and new lines / whitespace after it. Remove any unnecessary white space after that clo ... -
添加新的自定义帖子类型时,您需要刷新永久链接。 转到设置 - >管理员中的永久链接,然后点击保存。 When you add a new custom post type, you need to flush your permalinks. Go to Settings -> Permalinks in the admin and hit save.
-
wordpress自定义帖子类型(wordpress custom post type)[2022-02-23]
我找到了该怎么做。 我刚刚创建了一个名为“Products”的新页面并将其设置为posts页面。 然后我把它放在循环的前面 $ wp_query = new WP_Query(“post_type = product”); 它工作 I found what to do. I just created a new page called "Products" and set it as the posts page. Then I put this in front of the loop $wp_query ... -
解决方案1: 尝试删除您正在使用的模板文件中的侧边栏。 如果你想让你的内容全长,这将删除不需要的侧边栏。 解决方案2: 如果解决方案1不是要求,我相信你希望你的容器是全宽而没有任何填充或边距。 尝试找到容器区域并应用一些样式。 示例代码将如下所示, #primary .entry-content { width: 100% !important; } 解决方案3: 如果上述解决方案没有帮助,那么您可能需要一个特定的解决方案。 这将是一个儿童主题 。 有一篇关于如何通过它的儿童主题扩展你的二十七岁的博客 ...