JAVA: How to Solve Foreach Loop Remove/add Element Error

In fact, the reason for reporting an error is to throw an exception, which violates the fail fast protection mechanism

At this point, we replace the iterator to implement the loop

List<String> list=new ArrayList<>();
list.add("1");
list.add("2");
Iterator<String> iterator=list.iterator();
while(iterator.hasNext()){
    String item=iterator.next();
    if(Conditions for deleting elements){
        iterator.remove();
    }    
}


Exception Writing
for(String item:list){
    if(Conditions){
        list.remove(item);
    }
}

Vue Use scss Error: this.getOptions is not a function [How to Solve]

Background: an error is reported when installing sass for NPM

Installing sass through NPM

npm install node-sass
npm intall sass-loader

The above command installs the latest version. The reason for the error is that the latest version causes getoptions() incompatibility. The solution is to uninstall sass loader node sass and install the lower version. The commands are as follows

npm uninstall sass-loader //uninstall
npm install [email protected]  //install 8.0
npm uninstall --save node-sass
npm install [email protected] 

[Solved] there are special symbols in the initial password for installing MySQL in Hadoop, and an error is reported

Today, I installed a MySQL database in the server because there was a ‘)’ in the initial password assigned. I always reported an error when entering the password. I tried many changes on the Internet. It’s useless to wrap anything in quotation marks. Next, let’s talk about my solution:

Step 1:

vi /etc/my.cnf

After opening, add a sentence: skip grant tables

The function is equivalent to that no password is required for login

Step 2:

Restart MySQL

systemctl restart mysqld

Step 3:

Direct Logins

mysql -uroot -p

Step 4:

// goto database
use mysql
// refresh the data
flush privileges;

Step 5:

Change password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';

Then, delete the just secret free statement and restart MySQL

Login

mysql -uroot -p[NEW PASSWORD]

Chart.js Error: “Canvas is already in use. Chart …must be destroyed before the canvas can be reused”

when using jQuery to call webapi to obtain bubble chart data and draw bubble chart with chart.js in the test web page, if you click the display chart button twice, an error of “uncaught error: canvas is already in use. Chart with ID ‘0’ must be destroyed before the canvas can be reused.” will be reported.

from the error prompt, it should be that the canvas used to draw the bubble chart has been occupied, and there will be a conflict when using it to draw the graph again. Find two ways to solve this problem from chart.js official website and online

Call the chart.Destroy() function

The destroy function is introduced in the API help document of chart.js official website. This function is used to destroy the chart instance, clear the saved references in the object and the associated event listener. This function must be used before re using canvas to draw new graphics.
this article adds detection code before creating a new chart instance. If the mybubblechart object is already an instance of chart type, call the destroy function to destroy the instance

					if(myBubbleChart instanceof Chart)
                    {
                        myBubbleChart.destroy();
                    }
                    
                    myBubbleChart = new Chart(bubbleCanvas, {
                    type: "bubble",
                    data: data1,
                    options: []
                });

Clear/add canvas with jquery

Another way of learning as like as two peas in 2 is to remove the canvas element from jQuery before you create the chart instance, and then add the same canvas element, which is shown below:

            $('#bubbleChart').remove();
            $('#chartDiv').append('<canvas id="bubbleChart"></canvas>');

the above two methods support repeatedly clicking the display chart button to generate a bubble chart

[Solved] Decompression error: tar: Error is not recoverable: exiting now

Tar: error is not recoverable: exiting now

[root@node04 soft]# tar -zxvf apache-tomcat-8.0.53-x64.tar.gz

Error message:

gzip: stdin has more than one entry–rest ignored tar: Child returned status 2 tar: Error is not recoverable: exiting now

Solution 1: remove the Z parameter and use tar – xvf to decompress

Find or report an error.

Solution 2: use the unzip command.

Problem-solving.

If you cannot use the unzip command, first follow:

yum install -y unzip zip

How to Solve PIP3 error After upgrading pip3 install –upgrade pip

pip3 install –upgrade pip3 execution error after pip upgrade

Description
Traceback (most recent call last):
File “/home/brian/.local/bin/pip3”, line 7, in
from pip._internal.cli.main import main
File “/home/brian/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py”, line 60
sys.stderr.write(f”ERROR: {exc}”)
^
SyntaxError: invalid syntax

Solution
Execute python3 –version to determine the python3 version visit https://bootstrap.pypa.io/pip/ Find the get-pip.py file for the corresponding python version at this URL and execute wget in the terminal https://bootstrap.pypa.io/pip/3.8/get-pip.pypython3 get-pip.py

[Solved] Go Get Download Dependency Error: is not using a known version control system

Background

GoLand input command

C:\Users\HI\go\GoPack> go get -u github.com/gin-gonic/gin

Errors are reported as follows

package github.com/gin-gonic/gin: directory "C:\\Users\\HI\\go\\src\\github.com\\gin-gonic\\gin" is not using a known version control system

analysis

This problem belongs to dependency management, go module is an official version management tool launched after go1.11, and from go1.13, go module will be the default dependency management tool of go language
Enter go env to view the specific contents of go module. First, pay attention to go111module, which is the environment variable of go module , and the default is auto
when go111module = off, module support is not enabled. During compilation, dependencies will be found under gopath and vendor
when go111module = on, the module support is enabled. During compilation, the gopath and vendor dependencies will be ignored and downloaded directly from go. Mod
when go111module = auto, when the project is outside $gopath/SRC and there are go. Mod files in the project root directory, open the module support
.

Currently, there is no go.Mod in the root directory of the project I created, so the module supports closing by default

Solution:

 C:\Users\HI\go\GoPack> $env:GO111MODULE="on"

[Solved] MongoDB Error: TypeError: Object of type ObjectId is not JSON serializable

Scene description

After the MongoDB database is used to insert data, an error is reported when the flash restful interface is used to return data:

TypeError: Object of type ObjectId is not JSON serializable

Cause analysis

The reason for this problem is that when data is written to MongoDB, even if you do not specify a _id field, a field will be automatically generated for each piece of data _id, for example:

{
    "_id" : ObjectId("6180af3ef261f0827ea248d6"),
    "省份名称" : "澳门",
    "省份链接" : "https://www.gongkaoleida.com/area/3509",
    "省份代号" : "3509"
}

This field is of ObjectId type and cannot be returned using JSON serialization, so an error will be reported

Solution:

Since _id field cannot be converted and has no effect on our actual data. Then pop it up after inserting the data. An example is as follows:

self.db.filter_result.insert_one(item)
item.pop('_id')

Scrapy runs a crawler with an error importerror: cannot import name suppress

2021-11-02 15:56:03 [twisted] CRITICAL: 
Traceback (most recent call last):
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/crawler.py", line 104, in crawl
    six.reraise(*exc_info)
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/crawler.py", line 86, in crawl
    self.engine = self._create_engine()
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/crawler.py", line 111, in _create_engine
    return ExecutionEngine(self, lambda _: self.stop())
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/core/engine.py", line 67, in __init__
    self.scheduler_cls = load_object(self.settings['SCHEDULER'])
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/utils/misc.py", line 46, in load_object
    mod = import_module(module)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/core/scheduler.py", line 7, in <module>
    from queuelib import PriorityQueue
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/queuelib/__init__.py", line 1, in <module>
    from queuelib.queue import FifoDiskQueue, LifoDiskQueue
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/queuelib/queue.py", line 7, in <module>
    from contextlib import suppress
ImportError: cannot import name suppress

resolvent:

pip uninstall attrs
pip uninstall queuelib
pip install queuelib==1.5.0
pip install attrs

The Vue mobile terminal cannot use string.replaceall, and the error message is blank

When developing Vue, the replaceall function is used, and there is no problem debugging on the PC side

However, when packaging and deploying to the mobile end test, it is found that some pages are blank and the console only displays error {}

After troubleshooting, the replaceall function reports an error. Replace it with replace