以下代码逻辑有问题吗?case "课节": tempVal = cell.getStringCellValue(); if (tempVal != null) { lessons = tempVal.trim(); course.setLessons(Integer.valueOf(lessons)); } break; case "上课时间": if (tempVal != null) { startTime = tempVal.trim(); course.setStartTime(LocalTime.parse(startTime)); } case "下课时间": if (tempVal != null) { endTime = tempVal.trim(); course.setEndTime(LocalTime.parse(endTime)); }
时间: 2024-01-28 10:03:36 浏览: 24
是的,以上代码逻辑存在问题。在 "上课时间" 和 "下课时间" 这两个 case 中,没有像 "课节" 那样先判断 tempVal 是否为 null,直接对 tempVal 进行 trim() 操作和 parse() 操作会导致 NullPointerException。应该在这两个 case 中加上判断 tempVal 是否为 null 的条件语句,例如:
```
case "上课时间":
if (tempVal != null) {
startTime = tempVal.trim();
if (!startTime.isEmpty()) {
course.setStartTime(LocalTime.parse(startTime));
}
}
break;
case "下课时间":
if (tempVal != null) {
endTime = tempVal.trim();
if (!endTime.isEmpty()) {
course.setEndTime(LocalTime.parse(endTime));
}
}
break;
```
相关问题
java代码实现 无序链表 排序
可以使用冒泡排序、插入排序等算法来实现无序链表排序。
以冒泡排序为例,算法步骤如下:
1. 从链表头开始,设置游标指向链表开头节点。
2. 遍历链表,如果当前节点值大于后续节点值,则交换两节点值。
3. 当遍历到链表尾部时,回到链表头,重复步骤2,直到没有节点需要交换。
4. 遍历结束后,链表得以排序。
Java 代码示例:
```java
public class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
// 冒泡排序
public ListNode sortList(ListNode head) {
if (head == null || head.next == null) return head;
boolean flag = true;
while (flag) {
flag = false;
ListNode node = head;
while (node.next != null) {
if (node.val > node.next.val) {
int tempVal = node.val;
node.val = node.next.val;
node.next.val = tempVal;
flag = true;
}
node = node.next;
}
}
return head;
}
```
python gps数据采集
python的GPS数据采集可以通过串口助手将GPS模组数据提取出来,并保存为gps.txt文档,放到python脚本目录下。然后可以编写程序提取坐标信息。可以使用以下代码进行坐标信息提取:
```python
import math
def create_float_value(tmpfloat):
intPart = 0.0
fractPart = 0.0
fractPart, intPart = math.modf(tmpfloat)
tempVal1 = int(intPart / 100)
tempVal2 = int(intPart % 100)
tempVal3 = tempVal2 + fractPart
tempVal4 = tempVal3 / 60.0
tempVal5 = tempVal1 + tempVal4
return tempVal5
fp = open("gps.txt", 'r')
lines = fp.readlines()
longitude_list = []
latitude_list = []
for line in lines:
if line[:6] == '$GNGLL':
longitude_list.append(create_float_value(float(line.split(',')[3])))
latitude_list.append(create_float_value(float(line.split(',')[1])))
else:
continue
```
接下来,可以使用folium库将提取的WGS-84坐标直接带入使用,生成设备位置分布图。可以使用以下代码进行设备位置分布图的生成:
```python
import folium
map_info = folium.Map(location=[30.2813, 114.2352], zoom_start=12, control_scale=True)
for longitude, latitude in zip(longitude_list, latitude_list):
folium.Circle((latitude, longitude), radius=7, color='yellow', fill=True, fill_color='red', fill_opacity=0.7).add_to(map_info)
lenth = len(longitude_list)
for i in range(lenth):
folium.Marker(location=[latitude_list[i], longitude_list[i]], popup='点', icon=folium.Icon(icon='cloud')).add_to(map_info)
map_info.add_child(folium.LatLngPopup())
map_info.save('gps.html')
```
这样就可以将设备位置分布图保存为gps.html文件。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)