idea相关问题



? ? ? ? ?


2019.1版本的idea官方使用教程详解 https://www.jetbrains.com/help/idea/2019.1/using-code-editor.html

(编辑器中按【F1】即可到达该网址,该教程中包含idea的安装,使用,项目配置等的各个方面)


? ? ? ? ?


一.idea自身配置相关问题

? ubuntu下安装idea说明
? idea项目入门教程
? Intellij Idea中Backspace无法使用,Ctrl+c/Ctrl+d等等快捷键无法使用的问题的解决
? 关于我们自定义的快捷键的设置与取消
? idea自带快捷键使用说明
? idea字体大小设置
? 各个字符集编码问题解决
? 运行项目时的调试技巧




二.idea创建Spring Cloud项目相关问题

? IDEA创建SpringBoot无法连接的错误解决
?
?
?
?
?

























三.idea创建Java Application相关问题解决

? 解决:InvalidPathException
? 解决:找不到或无法加载主类
? 解决:长时间无反应而又不报错的程序运行












一.idea自身配置相关问题



1.ubuntu下安装idea说明

就单独说明一下Linux中idea的安装吧,Windows就应该不用说明了:)

Download IntelliJ IDEA网址:https://www.jetbrains.com/idea/download/

找到下载的软件包的位置

$dpkg -l | grep idea

解压

   把Idea放到你想要方的位置:sudo cp ideaIU-2018.1.6.tar.gz ~/下载
   解压:sudo tar -zxvf ideaIU-2018.1.6.tar.gz
   赋权限:sudo chmod 755 -R idea-IU-181.5540.7/

阅读README文件了解软件的安装方法

查看install-Linux-tar.txt(相当于README)文件发现启动console的方法:
  Linux Installation Instructions
  ------------------------------------------------------------------------------
  1. Unpack the IntelliJ IDEA distribution archive that you downloaded to
     where you wish to install the program. We will refer to this destination
     location as your {installation home} below.

  2. Open a console and cd into "{installation home}/bin" and type:

       ./idea.sh

     to start the application. As a side effect, this will initialize various
     configuration files in the ~/.IntelliJIdea2019.1 directory.

  3. [OPTIONAL] Add "{installation home}/bin" to your PATH environment
     variable so that you may start IntelliJ IDEA from any directory.

  4. [OPTIONAL] To adjust the value of the JVM heap size, create
      ~/.IntelliJIdea2019.1/config/idea.vmoptions (or idea64.vmoptions
      if using a 64-bit JDK), and set the -Xms and -Xmx parameters. To see how
      to do this, you can reference the vmoptions file under
      "{installation home}/bin" as a model.

注意:不能直接找到bin/idea.sh 打开,需要在终端中执行命令才会有效,进而才能启动后续的安装步骤。

在这里插入图片描述
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述




2.idea项目入门教程

下载完idea刚打开时,你可以点击最后一个Learn,即可使用idea的互动教程来学习idea的使用。
在这里插入图片描述





3.Intellij Idea中Backspace无法使用,Ctrl+c/Ctrl+d等等快捷键无法使用的问题的解决

http://www.cnblogs.com/biehongli/p/8214992.html
https://superuser.com/questions/327479/ctrl-space-always-toggles-chinese-ime-windows-7




4.关于我们自定义的快捷键的设置与取消

在学习快捷键的设置时:一不小心把line num的快捷键设成了1,orz!自此数字1就无法键入了,怒而摔桌!
步骤:

  • Ctrl+Shift+A+line num+Alt+Enter
  • 设置:输入你想为line num设置的快捷键
  • 删除:
    点击Alt+Enter界面的左下方的蓝色问号小图标即可直达官方帮助界面。
    用户设置的快捷键的文件位置:
    Windows
    Syntax
    %HOMEPATH%.\config\keymaps
    Example
    C:\Users\JohnS.IntelliJIdea2019.1\config\keymaps
    macOS
    Syntax
    ~/Library/Preferences//keymaps
    Example
    ~/Library/Preferences/IntelliJIdea2019.1/keymaps
    Linux
    Syntax
    ~/./config/keymaps
    Example
    ~/.IntelliJIdea2019.1/config/keymaps
    找到了配置文件的位置后使用任意一款编辑器打开该文件,删除掉你刚刚的设置即可。
    注意:要想使该修改生效,你需要重启idea或是重新加载idea的配置文件
    linux中可用source命令重新加载该配置文件,Windows中我就不知道了:)



5.idea自带快捷键使用说明

Editor Basics

  • Actions
    Ctrl+Shift+A? search all available actions without having to know their individual shortcuts
    输入命令:
    about:可以了解到你的idea产品的到期时间
    line num
    Delete Line
    最后键入Enter
  • Select
    Ctrl+Shift+右箭头 ? select code block
    Ctrl+W? extend code block
    Ctrl+Shift+W? shrink code block
    Ctrl+A? select all file
  • Comment file
    Ctrl+/? comment out | uncomment one or many line
  • Delete Line
    Ctrl+Y | Ctrl+Shift+A+Delete Line? Delete Line
    Ctrl+Z? recover delete line(undo)
  • Duplicate
    Ctrl+D? as Ctrl+C+Ctrl+D
  • Move
    Alt+Shift+上下箭头? move current line
    Ctrl+Shift+上下箭头? move whole method
  • Collapse
    Ctrl+ -? collapse a piece of code region
    Ctrl+ +? expand a piece of code region
    Ctrl+Shift+ -? collapse all
    Ctrl+Shift+ +? expand all
  • Multiple Selections
    Alt+J? select the symbol at the caret
    Alt+J? again to select the next occurence of this symbol
    Alt+Shift+J? deselect
    Ctrl+Alt+Shift+J? select all occurence of this symbol

Code Completion

  • Basic Completion
    Enter
    Ctrl+space
  • Smart Type Completion
    Ctrl+Shift+space? smart type completion filters the list of suggestions to include only those types that are applicable in the current context. Press Ctrl+Shift+space to see the list of matching suggestions.Choose one and then pressing Enter
    Ctrl+Shift+space+space? keep Ctrl+Shift pressed and then press space twice ,this can complet return statement
  • Statement Completion
    Ctrl+Shift+Enter

Refactoring
? 在此推荐一下《重构–既有代码的改善》?
重构总结:小步改动+每次改动后的测试

  • Rename
    Shift+F6
  • Extract Variable/Field
    Ctrl+Alt+V
  • Extract Method
    Ctrl+Alt+M
  • Extract Constatnt
    Ctrl+Alt+C
  • Extract Param
    Ctrl+Alt+P

Code Assistant

  • Code Formating
    Ctrl+Alt+L
    Ctrl+A+Ctrl+Alt+L
  • Param Info
    Ctrl+P
  • Quick Popups
    Ctrl+Q? see documentation for the symbol at the caret
    Esc? close popup menu
    Ctrol+Shift+I? see the definition for the symbol at the caret
  • Editor Coding Assistance
    F2? go to the netx error in the file
    Ctrl+F1? see error description
    Alt+Enter? select a solution
    Ctrl+Alt+T
    Ctrl+Shift+f7? highlight all usages of the symbol at the caret within the file

Navigation

  • Jump to Source
    F4
  • Declaration/Implementation
    Ctrl+B? jump to the declaration of a class or interface
    Ctrl+Alt+B? see implementation of a class/interface
  • File Structure
    Ctrl+F12? c:class m:method i:interface f:field
  • Next/Previous Occurences
    Ctrl+F? select a string in the code ,and then press Ctrl+F to call the find action.
    Enter | F3? find next occur
    Shift+F3? previous occur



6.idea字体大小设置

File---Settings
【Ctrl+Alt+S】快速打开Settings设置界面。
Editor的Fonts下可以调节字体大小及字体的风格

在这里插入图片描述




7.各个字符集编码问题解决

  • maven编码问题
    maven编译遇到"编码GBK的不可映射字符"警告的处理
    maven用的是win10的字符集,在winndows命令行输入chcp,返回936表示GBK
    而JAVA的字符集是UTF8,所以只要把maven编译时的字符集改为UTF8即可

    C:\Users\sky>chcp
    活动代码页: 936

  • 命令行运行程序存在的编码问题
    关于命令提示符中不能正常显示汉字的问题及解决

    C:\Users\sky\A\src\lexer>javac *.java
    Lexer.java:8: 错误: 编码 GBK 的不可映射字符 (0x97)
    //绫籐exer鐨勪富鏂规硶锛屽嵆鍑芥暟scan锛氳瘑鍒暟瀛楋紝鏍囪瘑绗﹀拰淇濈暀瀛?

  • Idea解决编码GBK/UTF-8的不可映射字符问题

    Setting->File Encodings->Project Encoding选择utf-8,Default encoding for properties files 也选择 UTF-8
    右键项目然后右键单击项目点击Rebuild Module重新加载项目

    File->Settings->File Encodings,将每个编码都设置为UTF-8
    同时将.idea文件夹下的encodings.xml中的charset设置删除即可

    [Ctrl+Alt+S]快速打开设置界面:在左上角搜索栏中输入encoding关键字,将Project Encoding改为UTF-8
    之后重新构建该模块项目:右键Rebuild Module
    在这里插入图片描述在这里插入图片描述

  • IDEA javadoc 编码GBK的不可映射字符
    用IntelliJ IDEA 生成javadoc时,在"Tools->Gerenate JavaDoc”面版的
    Other command line arguments 栏里输入:-encoding utf-8 -charset utf-8




8.运行项目时的调试技巧

  • 首先为错误问题的定位:
    可以通过设置调试级别的日志去定位问题,例如运行spring-cloud程序时可以将日志级别设置为debug,或者可以通过命令的选项,加上一个可以显示详细信息的选项,例如运行Java程序时:java命令的verbose选项。
  • 定位到具体的某个文件后,接下来利用idea提供的如下几个快捷键对该文件中的各个变量,方法逐一分析。

File Structure : Ctrl+F12

Parameter Info : Ctrl+P

Documentation : Ctrl+Q

Definition : Ctrl+Shift+I

Jump to Source : F4

Declaration : Ctrl+B

mplementation : Ctrl+Alt+B

Next/Previous Occurence :
Ctrl+F
Enter | F3
Shift+F3













二.idea创建Spring Cloud项目相关问题




1.IDEA创建SpringBoot无法连接的错误解决

在创建springboot项目的时候,使用IDEA新建springboot程序时
出现:IDEA创建SpringBoot无法连接的错误

解决:
进入到IDEA的setting
搜索 HTTP Proxy
选择Auto-detect proxy settings
点击最下面的Check connection弹出如下的输入框,输入地址https://start.spring.io点击ok,如果successful证明连接成功,即可生成springboot项目
在这里插入图片描述




















三.idea创建Java Application相关问题解决




1.解决:InvalidPathException

C:\Users\sky\IdeaProjects\compiler>javac lexer/*.java
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <*> at index 6: lexer/*.java
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
at java.base/java.nio.file.Path.of(Path.java:147)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at jdk.compiler/com.sun.tools.javac.main.Option$37.process(Option.java:693)
at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1088)
at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:381)
at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:193)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:229)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

路径问题:nvalidPathException为最主要的错误提示,compiler为你这个项目的主目录,而你要想编译你的项目需转到源码所在的目录,即src目录下进行编译。

C:\Users\sky\IdeaProjects\compiler>cd src
C:\Users\sky\IdeaProjects\compiler\src>javac lexer\*.java       //windows中的路径分割用左斜线,linux中的路径分割用右斜线
lexer\Lexer.java:8: 错误: 编码 GBK 的不可映射字符 (0x97)
//绫籐exer鐨勪富鏂规硶锛屽嵆鍑芥暟scan锛氳瘑鍒暟瀛楋紝鏍囪瘑绗﹀拰淇濈暀瀛?

由此可见成功解决了InvalidPathException异常,由于对Linux比较了解,解决此问题比较容易。
掌握Linux后在来看Windows的系统,也可以更好的理解其各个构成部分,而且最新的win10对权限的管理以及文件的提取都有向Linux靠拢的趋势。

上面由于是在Windows中执行的命令,故路径分割时,即lexer后面的那个路径分割符用的时左斜线,在Linux中你的路径分隔符要换成右斜线。

在idea的Terminal中即可查看java及javac命令的用法:
用法: javac <选项> <源文件>
使用 --help 可列出可能的选项

最后其实在idea中不需要进行编译,即无需你自己使用javac命令编译源代码,idea都默默为你做好了。




2. 解决:找不到或无法加载主类

参见:
https://blog.csdn.net/gxx_csdn/article/details/79059884
https://blog.csdn.net/bai_bug/article/details/79121109

C:\Users\sky\IdeaProjects\compiler>java main.Main
错误: 找不到或无法加载主类 main.Main
原因: java.lang.ClassNotFoundException: main.Main

问题1和2其实属于同一个问题:即你要在正确的目录下执行相应的命令,你要让你的命令可以作用于正确的路径,该路径是相对于命令提示符前面的那个路径而言的。绝对路径以左斜线(win)或右斜线(linux)开头,相对路径为当前路径下的各个可达路径。

javac:编译命令要在工程目录下的src目录下执行
java:运行命令要在编译后的字节码文件所在的目录下执行,idea中字节码文件存放在 out\production\工程名目录下

可以通过右击字节码文件所在的目录名,点击Open in Terminal快速打开在该目录下执行命令的终端窗口。
在这里插入图片描述




3.解决:长时间无反应而又不报错的程序运行

在Terminal终端窗口中运行程序时,程序不报错但是长时间不显示结果,即这是关于程序调试的问题,我们想让它显示程序运行时更加详细的信息,看看到底是卡在了哪里,关于java程序可以使用-verbose选项输出详细的执行过程。

C:\Users\sky\IdeaProjects\compiler\out\production\compiler>java main.Main i=1;

Run窗口中显示程序退出异常

“C:\Users\sky\IntelliJ IDEA 2019.1.2\jre64\bin\java.exe” “-javaagent:C:\Users\sky\IntelliJ IDEA 2019.1.2\lib\idea_rt.jar=50094:C:\Users\sky\IntelliJ IDEA 2019.1.2\bin” -Dfile.encoding=UTF-8 -classpath C:\Users\sky\IdeaProjects\compiler\out\production\compiler main.Main


Process finished with exit code -1

首先可以使用【win+R】打开一个终端窗口,运行java -h命令查看一下可以帮助到我们的选项,通过查找后发现-verbose选项可以帮助到我们

C:\Users\sky>java -h
用法:java [options] <主类> [args…]
(执行类)
或 java [options] -jar <jar 文件> [args…]
(执行 jar 文件)
或 java [options] -m <模块>[/<主类>] [args…]
java [options] --module <模块>[/<主类>] [args…]
(执行模块中的主类)
或 java [options] <源文件> [args]
(执行单个源文件程序)

将主类、源文件、-jar <jar 文件>、-m 或
–module <模块>/<主类> 后的参数作为参数
传递到主类。

其中,选项包括:

-cp <目录和 zip/jar 文件的类搜索路径>
 -classpath <目录和 zip/jar 文件的类搜索路径>
--class-path <目录和 zip/jar 文件的类搜索路径>
              使用 ; 分隔的, 用于搜索类文件的目录, JAR 档案
              和 ZIP 档案列表。
-p <模块路径>
--module-path <模块路径>...
              用 ; 分隔的目录列表, 每个目录
              都是一个包含模块的目录。
--upgrade-module-path <模块路径>...
              用 ; 分隔的目录列表, 每个目录
              都是一个包含模块的目录, 这些模块
              用于替换运行时映像中的可升级模块
--add-modules <模块名称>[,<模块名称>...]
              除了初始模块之外要解析的根模块。
              <模块名称> 还可以为 ALL-DEFAULT, ALL-SYSTEM,
              ALL-MODULE-PATH.
--list-modules
              列出可观察模块并退出
-d <module name>
--describe-module <模块名称>
              描述模块并退出
--dry-run     创建 VM 并加载主类, 但不执行 main 方法。
              此 --dry-run 选项对于验证诸如
              模块系统配置这样的命令行选项可能非常有用。
--validate-modules
              验证所有模块并退出
              --validate-modules 选项对于查找
              模块路径中模块的冲突及其他错误可能非常有用。
-D<名称>=<值>
              设置系统属性
-verbose:[class|module|gc|jni]
              启用详细输出
-version      将产品版本输出到错误流并退出
--version     将产品版本输出到输出流并退出
-showversion  将产品版本输出到错误流并继续
--show-version
              将产品版本输出到输出流并继续
--show-module-resolution
              在启动过程中显示模块解析输出
-? -h -help
              将此帮助消息输出到错误流
--help        将此帮助消息输出到输出流
-X            将额外选项的帮助输出到错误流
--help-extra  将额外选项的帮助输出到输出流
-ea[:<程序包名称>...|:<类名>]
-enableassertions[:<程序包名称>...|:<类名>]
              按指定的粒度启用断言
-da[:<程序包名称>...|:<类名>]
-disableassertions[:<程序包名称>...|:<类名>]
              按指定的粒度禁用断言
-esa | -enablesystemassertions
              启用系统断言
-dsa | -disablesystemassertions
              禁用系统断言
-agentlib:<库名>[=<选项>]
              加载本机代理库 <库名>, 例如 -agentlib:jdwp
              另请参阅 -agentlib:jdwp=help
-agentpath:<路径名>[=<选项>]
              按完整路径名加载本机代理库
-javaagent:<jar 路径>[=<选项>]
              加载 Java 编程语言代理, 请参阅 java.lang.instrument
-splash:<图像路径>
              使用指定的图像显示启动屏幕
              自动支持和使用 HiDPI 缩放图像
              (如果可用)。应始终将未缩放的图像文件名 (例如, image.ext)
              作为参数传递给 -splash 选项。
              将自动选取提供的最合适的缩放
              图像。
              有关详细信息, 请参阅 SplashScreen API 文档
@argument 文件
              一个或多个包含选项的参数文件
-disable-@files
              阻止进一步扩展参数文件
--enable-preview
              允许类依赖于此发行版的预览功能
要为长选项指定参数, 可以使用 --<名称>=<值> 或
--<名称> <值>。

接下来使用带-verbose选项的java运行命令查看详细记录

C:\Users\sky\IdeaProjects\compiler\out\production\compiler>java -verbose main.Main i=1;

最后发现它一直停在了[0.250s][info][class,load] inter.Access source: file:/C:/Users/sky/IdeaProjects/compiler/out/production/compiler/
该处便不在继续执行,因此我们就可以到此处去定位问题了。

接下来在idea中的做法为:
转到inter包下的Access类,利用idea提供的如下几个快捷键去解决问题:

  • File Structure : Ctrl+F12
  • Parameter Info : Ctrl+P
  • Documentation : Ctrl+Q
  • Definition : Ctrl+Shift+I
  • Jump to Source : F4
  • Declaration : Ctrl+B
  • Implementation : Ctrl+Alt+B
  • Next/Previous Occurence :
    Ctrl+F
    Enter | F3
    Shift+F3

即利用如上快捷键对该文件中设计的各个类及方法等逐一排查。









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

killingwill

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值