Tag Archives: development language

[Solved] JS Error: cannot set property xxx of undefined

case1

Error code

quizList[index] = currentQuiz;
quizList[index].learningItem = item;

Error content

Cannot read properties of undefined (reading 'learningItem')

Error reporting reason

currentQuiz object may be undefined, if you add the property learningItem to the undefined object quizList[index] dynamically, it will cause the error “cannot set property xxx of undefined”.

Solution:

quizList[index] = currentQuiz == undefined ?{} : currentQuiz;
quizList[index].learningItem = item;

Just judge whether the quizlist [index] is undefined

 

case2

Error code

quiz.finishedstudent.forEach(item => {
	if (item.score < 80) {
		errorNum++;
	}
})

Error content

Cannot read properties of undefined (reading 'forEach')

Solution:

if (quiz.finishedstudent != undefined) {
	quiz.finishedstudent.forEach(item => {
		if (item.score < 80) {
			errorNum++;
		}
	})
}

Tp6 Cannot enable error [How to Solve]

tp6 open error, you need to copy the root directory of .example.env, save it as .env, then modify the header to APP_DEBUG=true, and then directory config/app.php modify ‘show_error_msg’ => fales.

If the pdo still reports an error after starting php.ini again, log out the .env file

[DATABASE]
TYPE=mysql
HOSTNAME=host.docker.internal
DATABASE=easyadmin
USERNAME=root
PASSWORD=root
HOSTPORT=3306
CHARSET=utf8
DEBUG=true
PREFIX=ea_

 

[Solved] MindSpore Error: “operation does not support the type kMetaTypeNone“

Environment:
Hardware Environment(Ascend/GPU/CPU): All
Software Environment:
MindSpore version (source or binary): 1.6.0 & Earlier versions
Python version (e.g., Python 3.7.5): 3.7.6
OS platform and distribution (e.g., Linux Ubuntu 16.04): Ubuntu
GCC/Compiler version (if compiled from source): gcc 9.4.0
python code examples

from mindspore import nn

class Net(nn.Cell):
    def __init__(self):
        super(Net, self).__init__()

    def construct(self, x):
        return self.y + x

net = Net()
output = net(1)

Error reporting information

Traceback (most recent call last):
  File "test_self.py", line 11, in <module>
    output = net(1)
  File "mindspore\nn\cell.py", line 477, in __call__
    out = self.compile_and_run(*args)
  File "mindspore\nn\cell.py", line 803, in compile_and_run
    self.compile(*inputs)
  File "mindspore\nn\cell.py", line 790, in compile
    _cell_graph_executor.compile(self, *inputs, phase=self.phase, auto_parallel_mode=self._auto_parallel_mode)
  File "mindspore\common\api.py", line 632, in compile
    result = self._graph_executor.compile(obj, args_list, phase, self._use_vm_mode())
RuntimeError: mindspore\ccsrc\frontend\operator\composite\multitype_funcgraph.cc:162 GenerateFromTypes] The 'add' operation does not support the type [kMetaTypeNone, Int64].
The supported types of overload function `add` is: [Tuple, Tuple], [RowTensor, Tensor], [Tensor, Tensor], [List, List], [Tensor, List], [List, Tensor], [String, String], [Tuple, Tensor], [kMetaTypeNone, kMetaTypeNone], [Number, Number], [Number, Tensor], [Tensor, Number], [Tensor, Tuple].

The function call stack (See file 'rank_0/om/analyze_fail.dat' for more details):
# 0 In file test_self.py(8)
        return self.y + x

 

Solution:

Since the execution error is caused by using an undefined variable, the solution is to define the variable in the network’s initialization function __init__(self):. Note that only variables defined as members of self can be used in the construct(self, x) method.

from mindspore import nn

class Net(nn.Cell):
    def __init__(self):
        super(Net, self).__init__()
        self.y = 1.0

    def construct(self, x):
        return self.y + x

net = Net()
output = net(1)

If you write self.y = 1.0 instead of y = 1.0, you will also get an error because the variable is undefined.

Python Error: OSError: cannot open resource [How to Solve]

Question:

  File "D:\Windows_DL_Environment\anaconda3\envs\py37\lib\site-packages\PIL\ImageFont.py", line 852, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "D:\Windows_DL_Environment\anaconda3\envs\py37\lib\site-packages\PIL\ImageFont.py", line 212, in __init__
    font, size, index, encoding, layout_engine=layout_engine
OSError: cannot open resource

This class is a common font problem. In Windows environment, fonts are generally located in the C:\windows\fonts folder. In this folder, users can check whether the font specified in the python program exists.

fnt = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 50)

Solution 1:

Change the font that exists on the computer

ImageFont.truetype("Pillow/Tests/fonts/arial.ttf", 50)

Solution 2:

Found no freemono in the computer Ttf font, so you need to download
https://fontmeme.com/ziti/freemono-font/

After downloading, unzip it into the fonts folder

finally. Restart the computer to execute.

[Solved] ERROR SparkContext: Error initializing SparkContext. java.lang.IllegalArgumentException: System memo

During the actual operation of the recommendation system, the following errors occur when executing the featureengineering (Scala) file:
ERROR SparkContext: Error initializing SparkContext. java.lang.IllegalArgumentException: System memory 259522560 must be at least 471859200

Solution:
1. Click Edit configurations

2 If your setting interface has the following red box, paste the following text directly

-Xms128m -Xms512m -XX:MaxPermSize=300m -ea


3. If not, click Modify options first, then add VM options, as shown in the figure below, and then complete the second step

this problem should be solved.

Python parsing JSON Error: NameError: name ‘false’ is not defined

Python parses a JSON string and directly calls JSON.Loads error:

NameError: name 'false' is not defined

Solution:
use Python’s raw strings, that is, add R'''before the JSON string, and then add '' '. For example:

>>> import json
>>> json_string = r'''{"created_at":"Thu Jul 10 20:02:00 +0000 2014","id":487325888950710272,"id_str":"487325888950710272","text":"\u5f81\u9678\u300c\u5de6\u8155\u306e\u7fa9\u624b\u306f\u30db\u30ed\u3060\u300d","source":"\u003ca href=\"http:\/\/twittbot.net\/\" rel=\"nofollow\"\u003etwittbot.net\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1429838018,"id_str":"1429838018","name":"\u3053\u3093\u306a\uff30\uff30\u306f\u5acc\u3060\u3002","screen_name":"iyada_pp","location":"\u516c\u5b89\u5c40\u306e\u3069\u3053\u304b\u3002","url":null,"description":"\u3010\u3053\u3093\u306aPSYCHO-PASS\u306f\u5acc\u3060\u306a\u3011\u3068\u3044\u3046\u304f\u3060\u3089\u306a\u3044\u5984\u60f3bot\u3067\u3059\u3002\u30ad\u30e3\u30e9\u5d29\u58ca\u304c\u6fc0\u3057\u3044\u306e\u3067\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002","protected":false,"followers_count":99,"friends_count":98,"listed_count":5,"created_at":"Wed May 15 07:52:33 +0000 2013","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":12584,"lang":"ja","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/3661872276\/ab7201283dac5dc1789bb6dfa9b6abe4_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/3661872276\/ab7201283dac5dc1789bb6dfa9b6abe4_normal.jpeg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false,"filter_level":"medium","lang":"ja"}'''
>>> json.loads(json_string)

nested exception is java.lang.StackOverflowError [How to Solve]

The above is the error reported by the endpoint accessing oauth2, mainly because the configuration is not well configured, and the configuration before modification:


    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

Modified configuration:


    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.jdbcAuthentication()
                .dataSource(dataSource)
                .passwordEncoder(new BCryptPasswordEncoder());
    }

[Solved] pip Fatal error in launcher: Unable to create process using

Problem scenario

When we moved the python folder, the system’s global variables are still the original python path, at this time in cmd, type python, the system will follow the previous path to find python.exe, pip.exe. so you need to modify the global variables. But many friends then modify the global variables, although python is available, but pip still can not be used, will report the error pip Fatal error in launcher: Unable to create process using {original pip path} {now pip path}.

Problem analysis

This is because pip is actually python code, pip inside the python interpreter path or the original path is not updated, modify the system global variables and will not affect the python path in the pip.exe file.

Problem-solving:

The brute force solution is to directly modify the python path inside pip.exe. Note that pip.exe is a binary file and cannot be modified directly.

1. Download and open binary software (WinHex, hedit)

2. Modify and save the file

Modify and save directly on the right