Java程序报错总结

1.空指针异常:编译通过,但是运行时显示空指针异常。

  • 在本类属性中,有其它类的引用,再使用这个引用前是否给其new对象,赋地址。
class Computer
{
	String name;
	String datea;
	String color;
}
class Student
{
	int xuehao;
	String name;
	Computer a;
}
public class FirstBlood
{
	public static void main(String[] args){
		Computer aaa= new Computer();
		Student  xxx =new Student ();
		//xxx.a=aaa;**(报错原因为这里,起初并没有将应用aaa的地址赋值给引用xxx.a,这条语句说明了两个对象之间的联系)**
		xxx.a.name="apple";
		xxx.name = "Jia";
		System.out.println(xxx.a.name);
		System.out.println(xxx.name);

	}
}

2.写调用函数时,一直显示错误

  • 调用函数的语句没有写在方法体中(主方法只不过是程序的入口,不要将其特殊化,除此外跟其他方法没有区别)

3.程序无法运行

  • main方法的形参是否没有写?

4.Scanner类关闭后再次使用其方法

  • 由于所有的scanner类共享一个输入流,当其中一个调用关闭函数的时候,所有的scanner对象都关闭了。
  • 所以建议大家在编写程序时,在不同地方使用scanner类的时候,注意只需调用一次close方法,并且要注意在此后无任何读控制台操作。

5.JDBC连接数据库时:报警告

Mon Apr 27 14:17:39 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification

翻译:不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果没有设置显式选项,则默认情况下必须建立SSL连接。您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任存储。

原因:MySQL在高版本需要指明是否进行SSL(保障Internet数据传输安全利用数据加密)

解决:在连接数据url后上添加 useSSL=false
如:

url=jdbc:mysql://localhost:3306/xingkong?useSSL=false

注意:xingkong为数据库。
如果你安装数据库的时候没有配置参数文件,即有多个参数记得用&连接,例如
也许你需要写出这样:

jdbk:mysql://localhost:3306/xingkong?characterEncoding=utf-8&useSSL=false

6.使用git时报错:

Warning: Permanently added the RSA host key for IP address
‘13.229.188.59’ to the list of known hosts.

解决方案:
在C:\Windows\System32\drivers\etc\hosts文件添加

‘13.229.188.59’ github.com 根据自己的Ip修改

1.再查看公钥是否添加成功时报:

The authenticity of host ‘github.com (52.74.223.119)’ can’t be
established. RSA key fingerprint is
SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you
want to continue connecting (yes/no/[fingerprint])?

解决方案:输入yes即可
这时会生成一个konwn_hosts文件

第一次push报错

假如外出工作,需要在另一台电脑上面pull自己的某个git远程项目到本地;

 git init
 
 git pull https://github.com/TTyb/54qjLogin   (远程仓库url)

push报错:

$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
 
    git remote add <name> <url>
 
and then push using the remote name
 
    git push <name>

解决方案:git remote用法

这个时候第一次push需要网址:
 
$ git add --all
$ git commit -m "提交信息"
$ git remote add origin '远程仓库url'
$ git push -u origin 对应远程分支名
 
 
 
然后下一次就不用那么麻烦了,直接:
 
$ git add --all
$ git commit -m "信息"
$ git push

3.push时报错

1、在manage文件夹里打开git,输入git init初始化本地仓库,GitHub创建远程仓库manage

2、以下命令关联本地和远程仓库,*****为我的用户名
3.本地已经有项目代码了在add和commit之后,想要push到远程仓库

git remote add origin git@github.com:******/manage.git
git push origin master

此时报错:
! [rejected] master -> master (non-fast forward)
解决方案:
1、git pull origin master --allow-unrelated-histories //把远程仓库和本地同步,消除差异

2、重新add和commit相应文件

3、git push origin master

4、此时就能够上传成功了
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值