Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution

The source code is as follows:

        Point[] points = new Point[n];//Point is a class
         for ( int i=0;i<n;i++ ) { 
            System.out.print( "Please enter x:" ); 
            points[i]. setX(in.nextInt());//The 29th line 
            System.out.print( "Please enter y:" ); 
            points[i].setY(in.nextInt()); 
        }

The error message is as follows:

Exception in thread “main” java.lang.NullPointerException
at test.Main.zjd(Main.java:29)
at test.Main.main(Main.java:9)

analysis:

Point[] points=new Point[n];//After defining the class array, I thought that the above code could be used directly, but the above error was reported. 
So I set line 29 as a breakpoint, and 
when I started Debug and run to this point, I found the problem:

It is found in the variable list that the values ​​of points[0] and points[1] are all null

It seems that there is no problem at a glance, but when you think about it, each element in the array is an object. Since it is an object, how can we use it without allocating space (without new)?

Modified code:

        Point[] points= new Point[n];
         for ( int i=0;i<n;i++ ) {
            points[i] =new Point(); //Solution: apply for allocating space for the elements in the class array here . 
            System.out.print( "Please enter x:" ); 
            points[i].setX(in.nextInt()); 
            System.out.print( "Please enter y:" ); 
            points[i].setY(in .nextInt()); 
        }

The problem of using GB2312 encoding in .NET Core to report errors

wrong description

surroundings

  • dotnet 2.1.4

phenomenon

When used in code

System.Text.Encoding.GetEncoding("GB2312")
//or
System.Text.Encoding.GetEncoding("GBK")

Will throw an exception:

Unhandled Exception: System.ArgumentException:’GB2312′ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

or

Unhandled Exception: System.ArgumentException:’GBK’ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

solve

the reason

Use the following code to check the supported encoding:

System.Text.Encoding.GetEncodings();

It is found that there is no GB2312 or GBK in the obtained code.

Solution

first step

Add the following packages to the project:

System.Text.Encoding.CodePages

According to the description of System.Text.Encoding.CodePages nuget homepage , this package can provide programs with Windows-1252, Shift-JIS, and GB2312 encodings.

Provides support for code-page based encodings, including Windows-1252, Shift-JIS, and GB2312.

So after importing this package, we will be able to use GB2312 encoding.

In the .csprojdocument should add the following code:

  <ItemGroup>
    <PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
  </ItemGroup>

Or execute the following command in the project directory:

dotnet add package System.Text.Encoding.CodePages --version 4.4.0

Of course, the version number needs to be modified to the latest. At this time (2018.02.22) the latest version is 4.4.0.

Don’t forget to execute dotnet restore.

Second step

According to error, we need to use coded references Encoding.RegisterProviderto register functions.

In use System.Text.Encoding.GetEncoding ("GB2312")prior to execution in the code:

System.Text.Encoding.RegisterProvider (System.Text.CodePagesEncodingProvider.Instance);

After registering, you won’t get an error when you get the GB2312 code object, and you can use the functions normally.

MYSQL gruop by Error: this is incompatible with sql_mode=only_full_group_by

The following error is reported when searching or inserting data in the mysql tool:
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘database_tl.emp.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
the reason:
Take a look at the syntax of group by:
select select the column in the group + aggregate function from the table name group by grouped column 
From the perspective of grammatical format, the grouping is first, and then the columns to be retrieved are determined. The columns to be retrieved can only be selected among the columns participating in the grouping.
My current Mysql version 5.7.17,
Look again at ONLY_FULL_GROUP_BY means: for the GROUP BY aggregation operation, if the column in the SELECT does not appear in the GROUP BY, then this SQL is illegal, because the column is not in the GROUP BY clause, that is to say, it is detected The column must appear after the group by, otherwise an error will be reported, or this field appears in the aggregate function.
View the mysql version command: select version();
View the sql_model parameter command:
SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;
Find:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
The first item turns ONLY_FULL_GROUP_BY by default,
Solution:
1. Select only the columns that appear behind the group by, or add aggregate functions to the columns; (not recommended)
2. Command line input:
set @@GLOBAL.sql_mode=”;
set sql_mode =’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;
Turn off ONLY_FULL_GROUP_BY by default!
Use the tool to select at this time
SELECT @@sql_mode;
SELECT @@GLOBAL.sql_mode;
Found that ONLY_FULL_GROUP_BY does not exist anymore, it feels OK. But if you restart the Mysql service, you will find that ONLY_FULL_GROUP_BY will still exist
If you want to completely solve this problem, you have to change the my.ini configuration (if your mysql does not have this file, change my-default.ini to my.ini, my version does not have the my.ini configuration problem)
Add under [mysqld] and [mysql]
 sql_mode =’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;

How to Solve Error: Unsupported field: HourOfDay

Error: Unsupported field: HourOfDay

code show as below

LocalDate now = LocalDate.now();
String year = now.format(DateTimeFormatter.ofPattern("yyyy"));
String hour = now.format(DateTimeFormatter.ofPattern("MM-dd-HH"));

The error is as follows

Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay
	at java.time.LocalDate.get0(LocalDate.java:680)
	at java.time.LocalDate.getLong(LocalDate.java:659)
	at java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:298)
	at java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2540)
	at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2179)
	at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1746)
	at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1720)
	at java.time.LocalDate.format(LocalDate.java:1691)
	at com.feiyangshop.recommendation.HdfsHandler.main(HdfsHandler.java:21)

I also traced it to the jdk source code to view it.

private int get0(TemporalField field) {
        switch ((ChronoField) field) {
            case DAY_OF_WEEK: return getDayOfWeek().getValue();
            case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1;
            case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
            case DAY_OF_MONTH: return day;
            case DAY_OF_YEAR: return getDayOfYear();
            case EPOCH_DAY: throw new UnsupportedTemporalTypeException("Invalid field 'EpochDay' for get() method, use getLong() instead");
            case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1;
            case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
            case MONTH_OF_YEAR: return month;
            case PROLEPTIC_MONTH: throw new UnsupportedTemporalTypeException("Invalid field 'ProlepticMonth' for get() method, use getLong() instead");
            case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
            case YEAR: return year;
            case ERA: return (year >= 1 ? 1 : 0);
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }

Finally, the code that throws the exception is here.

I explained in now.format(DateTimeFormatter.ofPattern("MM-dd-HH"));the HHis not caseamong.

Why caseis there only year, month and day, and no hour, minute and second?

emmmmm.

The answer is: I used the wrong class

LocalDateTimeThis class should be used . This class contains hours, minutes and seconds.

LocalDateTime now = LocalDateTime.now();
String year = now.format(DateTimeFormatter.ofPattern("yyyy"));
String hour = now.format(DateTimeFormatter.ofPattern("MM-dd-HH"));

How to Solve jQuery error: Uncaught ReferenceError: $ is not defined

When using jQuery, I found the following error:

Uncaught ReferenceError: $ is not defined (anonymous function)

The reason for this error:

1. The path of the jQuery library file is wrong. Checking whether the file path is correct can usually solve the error.

2. If the path of the library file is correct, the order of loading the jQuery library file in the html may be wrong. If the jQuery library file is loaded at the very beginning, the error can be solved.

Mybatis error under Springboot project: Invalid bound statement (not found)

Mybatis reports an error: Invalid bound statement (not found). There are many reasons, but just like the error message, the SQL statement in the xml cannot be found. There are three situations in which the error is reported:

The first type: grammatical error

Java DAO layer interface

public  void delete(@Param("id")String id);

Mapper.xml file corresponding to Java

<? xml version="1.0" encoding="UTF-8" ?> 
<! DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis -3-mapper.dtd" > 
< mapper namespace ="xxx.xxx.xxx.Mapper" > 
    <!-- Delete data --> 
    < delete id ="delete" parameterType ="java.lang.String" >
        DELETE FROM xxx WHERE id=#{id}
    </ delete > 
</ mapper >

Check: 1. Whether the method name (delete) in the interface is consistent with id=”delete” in the xml file

2. Whether the path in namespace=”xxx.xxx.xxx.Mapper” in the xml file is consistent with the interface file path

3. Whether parameterType and resultType are accurate; resultMap and resultType are different.

The second: compilation error

Locate the project path: under the error path in target\classes\, and look for the corresponding xml file.

(1) If there is no corresponding xml file, you need to add the following code in pom.xml:

< build > 
    < resources > 
         < resource > 
             < directory > src/main/java </ directory > 
             < excludes > 
                 < exclude > **/*.java </ exclude > 
             </ excludes > 
         </ resource > 
         < resource > 
             < directory > src/main/resources </ directory > 
             < includes > 
                 < include >**/*.* </include > 
             </ includes > 
        </ resource > 
    </ resources > 
</ build >

Delete the files in the classes folder, recompile, and the corresponding xml file will appear.

(2) If there is an xml file, open the xml file and check whether the error part is consistent with the source file.

First clear the files in the classes folder, execute the command: mvn clean to clean up the content, and then recompile.

The third type: configuration error

  When specifying the scan package in the configuration file, there is a problem with the configuration path. For example: the “basePackage” attribute package name specified in the spring configuration file must be specific to the package where the interface is located, instead of writing the parent or higher level package, otherwise problems may occur; cn.dao and cn.* may also cause errors ; When the annotation is scanned, the package may not be scanned.

[Solved] ora 01033 linux,ORA-01033: ORACLE initialization or shutdown in progres

ORA-01033: ORACLE initialization or shutdown in progres

2009-01-20 15:22

If it is because of careless manual deletion, oracle data files (such as table space) and this error generated. Then there is help.

Methods as below:

First find the BIN under oracle_home, for example (oracle\product\10.2.0\db_2\bin), find sqlplus.exe in this directory and run it. then

SQL>connect sys/user password as sysdba

SQL>shutdown normal

SQL>startup mount

SQL>alter database open;

alter database open

*

There is an error on line 1:

ORA-01157: unable to identify/lock data file 5-see DBWR trace file

ORA-01110: data file 5:’F:/ORACLE/TEST01.DBF’

It can be concluded that it is caused by the data file deletion operation. Next:

SQL> alter database create datafile 5;

The database has been changed.

SQL> alter database datafile 5 offline drop;

The database has been changed.

Then test it

SQL> conn scott/tiger

ERROR:

ORA-01033: ORACLE initialization or shutdown in progres

Warning: You are no longer connected to ORACLE.

Failed, log in again.

SQL> conn system/oracle as sysdba;

Retest

SQL> conn scott/tiger

ORA-01157: unable to identify/lock data file 6-see DBWR trace file

ORA-01110: data file 6:’F:/ORACLE/TEST01.DBF’

This means that you have deleted more than one file.

Repeating the above operation is nothing more than changing datafile 5 to datafile 6. Until SQL> conn scott/tiger can connect normally.

Note: The above SQL> conn scott/tiger test premise is that the scott user has been unlocked. You can also change to another user name (or you can define it yourself) to test.

————————————————– ——————–

When the client Oracle server enters PL/SQL Developer, it reports ora-01033: oracle initializationg or shutdown in progress, indicating that the application system cannot connect to the Oracle service. Solve the problem through remote guidance. The process is as follows:

1. Enter CMD and execute set ORACLE_SID=fbms to ensure that it is connected to the correct SID;

2. Run sqlplus “/as sysdba”

SQL>shutdown immediate stop service

SQL>startup Start the service, observe whether there is an error when the data file is loaded at startup, and remember the label of the error data file

SQL>shutdown immediate stop the service again

SQL>startup mount

SQL> recover datafile 2 Recover error data file

SQL>shutdown immediate stop the service again

SQL>startup starts the service, this time it is normal.

3. Enter PL/SQL Developer to check, and no more errors are prompted.

————————————————– —————

Solution to oracle error ora-01658 2008-07-23 11:04 This error is reported that the size of the oracle table space is insufficient. First check all tables

Room size:

SELECT T.TABLESPACE_NAME, ROUND(SUM(BYTES/(1024 * 1024)), 0) TS_SIZE

FROM DBA_TABLESPACES T, DBA_DATA_FILES D

WHERE T.TABLESPACE_NAME = D.TABLESPACE_NAME

GROUP BY T.TABLESPACE_NAME;

Then query the data file name of the table space to be modified:

select file_name,blocks,tablespace_name

from dba_data_files

Write down the path of the dpf file corresponding to the table space. For example,’/opt/oracle/oradata/TEST/test.dbf’

Finally modify the table space data file:

ALTER DATABASE DATAFILE’/opt/oracle/oradata/TEST/test.dbf’ RESIZE 2000M;

[Solved] Incompatibile SockJS! Main site uses: “1.5.0”, the iframe: “1.0.0”. at s (VM6 sockjs.min.js:2) version issue

Incompatibile SockJS! Main site uses: “1.5.0”, the iframe: “1.0.0”. at s (VM6 sockjs.min.js:2) When

starting the service today, I got this error inexplicably, I thought it was my code There was a problem, Baidu search found that everyone said that the problem of nginx reverse proxy, I did not install nginx! nginx! nginx!
So I checked my package-lock.json and modified the sockjs-client version to 1.5.1, and reinstalled the dependency on npm i and it was ok.

 

Android: How to Solve Execution failed for task ‘:app:compileDebugJavaWithJavac‘. > javax/xml/bind/JAXBException

I recently upgraded Android studio 4.1.3 to the latest version 4.2.1, and the following error was reported when running the project:

The following project options are deprecated and have been removed:
android.databinding.enableV2
Databinding v1 is removed.

Unable to load class ‘javax.xml.bind.JAXBException’.

This is an unexpected error. Please file a bug containing the idea.log file.

Execution failed for task ‘:app:compileDebugJavaWithJavac’.
> javax/xml/bind/JAXBException

I was puzzled. I searched the Internet and found the reason. The Databinding framework requires Java 8 and below. The above version lacks some classes.

The new version of AS comes with 11, and then the jdk path is changed to 8, but it is not allowed to change, theoretically it should be possible to change it, there is no way, only the one before installation

AS4.1.3 version, and then run the project OK. Of course, this method is conservative and safe. If you have to use JDK11, it is estimated that the project will be changed.

[Solved] Error creating bean with name rController‘: Unsatisfied dependency expressed through field

Problem Description:

@Override
Error creating bean with name 'ucenterMemberController': Unsatisfied dependency expressed through field 'ucenterMemberService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ucenterMemberServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.atguigu.educenter.mapper.UcenterMemberMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Cause Analysis:
Noted one sentence of the error: No qualifying bean of type’com.atguigu.educenter.mapper.UcenterMemberMapper’ available: expected at least 1 bean which qualifies as autowire candidate. It means that the mapper is not scanned, and it needs to be added to the startup class. Scan the mapper’s comments

solution:

There was a mistake here, so the mapper was not scanned, so an error was reported.

Solved: No’Access-Control-Allow-Origin’ cross-domain issue

This article mainly introduces the solution: No’Access-Control-Allow-Origin’ cross-domain, the article introduces it in detail through the sample code, and has a certain reference learning value for everyone’s study or work. Friends who need it will follow Let’s study together with the editor

problem analysis:

This is a common cross-domain request problem, which is common in projects where the front and back ends are separated. The request path in the front-end project directly uses the back-end request path (for example: http://192.168.1.1:8080/demo/getUser.do), but According to the browser’s network request rules, the background server is not allowed to call directly in this way (it will be intercepted by malicious hackers). As a result, the cross-domain request was rejected (as shown below).

Access to XMLHttpRequest at’http://192.168.1.1:8080/app/easypoi/importExcelFile’ from origin’http://localhost:8080′ has been blocked by CORS policy: No’Access-Control-Allow-Origin’ header is present on the requested resource.

Solution:

Many on the Internet allow to modify the configuration files in various projects, but it is not easy to use. In fact: only need to modify a filtering configuration of the background server (such as java’s tomcat) to allow cross-domain requests;

Add the following configuration filter to the conf/web.xml configuration file of the requested server (tomcat)

(For example, when there are multiple filters in web.xml, put the following configuration at the forefront)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<filter>
 <filter-name>CorsFilter</filter-name>
 <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
 <init-param>
   <param-name>cors.allowed.methods</param-name>
   <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
 </init-param>
 <init-param>
   <param-name>cors.allowed.headers</param-name>
   <param-value>Access-Control-Allow-Origin,Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
 </init-param>
 <async-supported>true</async-supported>
</filter>
<filter-mapping>
 <filter-name>CorsFilter</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping>

In this way, cross-domain requests are allowed on the root (back-end), and there are also malicious injections by hackers that cause the server to be paralyzed (except for the intranet or stand-alone version).