Tag Archives: ProgrammerAH

Java lossy conversion

Click on the blue words in the upper left corner and follow “Big Guy outside the pot”

Focus on sharing the latest foreign technology content

1. An overview of the
In this quick tutorial, we’ll discuss the concept of lossy transformations in Java and the reasons behind them.
In the meantime, we’ll explore some convenient transformation techniques to avoid this error.
2. Lossy conversion
Lossy transformation is the loss of information while processing data.
In Java, this corresponds to the possibility of losing variable values or precision when converting from one type to another.
When we try to convert a variable of a high-level type to a low-level type, Java will generate an incorrect, incompatible type when compiling the code: a potentially lossy conversion.
For example, let’s try assigning a long value to an int value:

long longNum = 10;	
int intNum = longNum;

When compiling this code, Java produces an error:

incompatible types: possible lossy conversion from long to int

Here, Java will find that long and int are incompatible and cause lossy conversion errors. Because you can have long values outside of the int range of -2,147,483,648 to 2,147,483,647.
Similarly, we try to assign a long to a float:

float floatNum = 10.12f;	
long longNum = floatNum;	
incompatible types: possible lossy conversion from float to long

Because floats can represent small values that don’t have a corresponding long type. Therefore, we will receive the same error.
Similarly, converting a double to an int results in the same error:

double doubleNum = 1.2;	
int intNum = doubleNum;	
incompatible types: possible lossy conversion from double to int

The double value may be too large or too small for an int value, and the small value will be lost in the conversion. Therefore, this is a potentially lossy transformation.
In addition, we may encounter this error when performing a simple calculation:

int fahrenheit = 100;	
int celcius = (fahrenheit - 32) * 5.0/9.0;

When a double is multiplied by an int, the result is a double. Therefore, it is also a potentially lossy transformation.
Therefore, incompatible types in lossy conversions can have different sizes or types (integer or decimal).
3. Basic data types
In Java, there are many basic data types and their corresponding wrapper classes.
Next, let’s make a list of all possible lossy transformations in Java:
short to byte or charchar to byte or shortint to byte, short or charlong to byte, short, char or intfloat to byte, short, char, int or longdouble to byte, short, char, int, long or float
Note that although short and CHAR have the same range. However, the conversion from short to char is lossy because char is an unsigned data type.
4. Transform technology
4.1. Conversion between two basic data types
The simple way to avoid lossy conversions for primitive types is by casting down; In other words, cast a high-level type to a low-level type. For this reason, it is also called a narrowing primitive conversion.
For example, let’s convert long to short using a downward cast:

long longNum = 24;	
short shortNum = (short) longNum;	
assertEquals(24, shortNum);

Similarly, convert a double to an int:

double doubleNum = 15.6;	
int integerNum = (int) doubleNum;	
assertEquals(15, integerNum);

However, we should note that casting down a high-level type with a value too large or too small to a low-level type can result in unexpected values.
We convert a long value to a value outside the range of the short type:

long largeLongNum = 32768; 	
short minShortNum = (short) largeLongNum;	
assertEquals(-32768, minShortNum);	

	
long smallLongNum = -32769;	
short maxShortNum = (short) smallLongNum;	
assertEquals(32767, maxShortNum);

If we look closely at the transformations, we see that these are not the expected values.
In other words, when Java is converting from a high-level type to a low-level type, when the maximum value of the low-level type is reached, the next value is the minimum value of the low-level type, and vice versa.
Let’s look at an example to understand this. When largeLongNum with a value of 32768 is converted to short, the value of shortNum1 is -32768. Since the maximum value of short is 32767, Java will select the next minimum value of short.
Similarly, when smallLongNum is converted to short. ShortNum2 has a value of 32767, which Java USES as the next maximum for Short.
Also, let’s look at what happens when we convert the maximum and minimum values of long to ints:

long maxLong = Long.MAX_VALUE; 	
int minInt = (int) maxLong;	
assertEquals(-1, minInt);	

	
long minLong = Long.MIN_VALUE;	
int maxInt = (int) minLong;	
assertEquals(0, maxInt);

4.2. Convert between wrapper objects and primitive types
To convert the wrapper object directly to the base type, we can use various methods in the wrapper class, such as intValue(), shortValue(), and longValue(). This is called unpacking.
For example, let’s convert a Float object to a long:

Float floatNum = 17.564f;	
long longNum = floatNum.longValue();	
assertEquals(17, longNum);

In addition, if we look at the implementation of longValue or similar methods, we will find the use of narrowing the original transformation:

public long longValue() {	
    return (long) value;	
}

However, sometimes you should avoid narrowing the original transformation to preserve valuable information:

Double doubleNum = 15.9999;	
long longNum = doubleNum.longValue();	
assertEquals(15, longNum);

After conversion, the value of longNum is 15. However, doubleNum is 15.9999, very close to 16.
Instead, we can use math. round() to convert to the nearest integer:

Double doubleNum = 15.9999;	
long longNum = Math.round(doubleNum);	
assertEquals(16, longNum);

4.3. Convert between wrapper objects
To do this, let’s use the transformation techniques we’ve already discussed.
First, we will convert the wrapper object to a base value, cast it down and convert it to another wrapper object. In other words, we will perform unboxing, downcast, and boxing techniques.
For example, let’s convert a Double object to an Integer object:

Double doubleNum = 10.3;	
double dbl = doubleNum.doubleValue(); // unboxing	
int intgr = (int) dbl; // downcasting	
Integer intNum = Integer.valueOf(intgr);	
assertEquals(Integer.valueOf(10), intNum);

Finally, we use intet.valueof () to convert the basic type int to an Integer object. This type of conversion is called boxing.
5. To summarize
In this article, we explored the concept of lossy transformations in Java through examples. In addition, we have written a handy list of all possible lossy transformations in Java.
Along the way, we’ve determined that narrowing the original transform is an easy way to transform the base type and avoid lossy conversion errors.
At the same time, we explored other convenient techniques for numeric conversion in Java.
The code implementation for this article can be found on the GitHub project.  
From spring for All community Translation group


Recently, I have translated the articles into PDF.
Reply in the background of official account: 002 can get oh ~
The content of PDF will be updated continuously in the future, please look forward to it!

● Top 10 mistakes you make using the Spring Framework
● Why Spring as the Java framework?
●Solr full-text search
Top right button to share with more people ~

Here we are. Click and watch before you go

error C2784: ‘bool std::operator <(const std::_Tre

Error 42, Error C2784: ‘bool STD ::operator < (const std::_Tree< _Traits> & ,const std::_Tree< _Traits> &) ‘ : could not deduce template argument for ‘const std::_Tree< _Traits> & ‘From ‘const STD :: String’ d:\ Program files_x86\ Microsoft Visual Studio 9.0\ VC \include\ Functional 143 Test

If the above error occurs when using STL container insert methods such as map, and there are no syntax errors elsewhere, it is likely that no header #include &lt is imported. string>

Red rice note3 (Kenzo) is brushed into lineage OS

The red mi Note3 (kenzo) is brushed into the process of Lineage OS

For a detailed tutorial, see Install LineageOS on kenzo
for some additional additions

0 Preparation before swiping
If you have logged in to Google account, first delete the Google account of this machine (very important, otherwise the boot wizard cannot skip, people outside the wall or with *** network can ignore) if you are using mobile Authenticator, please note: “Please go to this page to close secondary verification before uninstalling the verifier and restoring the mobile phone”. I’ve turned off my secondary verification and reloading. Backup important data
1 update Recovery
The first step encountered difficulty, and the fastboot refresh TWRP prompt FAILED. After checking the reason, it turned out to be the lock problem of Xiaomi. That is to say, even if it has been unlocked once, if you see such a prompt, then download the unlock tool of Xiaomi again and just click to unlock it again.
2 Installation of Lineage OS
Put the downloaded Lineagexx.zip into SDCard, and then enter Recovery. First, the Data, including System, Data, Cache and Davik Cache, will be cleaned. Because I was updating from the CM system, so the Lineage had to be erased. Then go back to select the installation, select the package into the compression, slide to confirm the brush. Then I ran into a problem and told me “ZIP Signature Verification failed”. I tried not to select the annoying ZIP verification, but it failed again. The error was different.

xiaomi.verify.modem() failed to read current MODEM version: -2

Update process ended with ERROR: 7

See this post for an explanation of the problem. The main reasons are:

The blobs used by system are taken from MIUI Global DEV ROM expect the firmware to be from the same release too. Mismatch in that can cause issues.

The solution, some netizens suggested, was to brush the latest version of MIUI and then brush the Lineage. The method was a bit awkward, mainly because the ROM of MIUI was too big, too expensive, too, the SHU too often eight or nine hundred trillion. The solution was found by myself: Status 7 Error with CWM or TWRP Recovery on Crinum Android! . The general idea is the same as this one, with some minor changes. The unzipped upater-script begins as follows:

assert(getprop("ro.product.device") == "kate" || getprop("ro.build.product") == "kate" || getprop("ro.product.device") == "kenzo" || getprop("ro.build.product") == "kenzo" || abort("E3004: This package is for device: kate,kenzo; this device is " + getprop("ro.product.device") + "."););
assert(xiaomi.verify_modem("MSM8976.LA.1.0.c3-30041-STD.PROD-1.77504.1.83742.1") == "1");

Considering the error message when I flash for xiaomi. Verify the modem () mistake, so I'm going to the second row assert to delete, and then brush into the compressed again and again, remember not to select the zip signature check, then brush into the lineage OS the success, remember to Gapps package also brush into the boot, again has been switched on, then brush in the rear into the Gapps remember dual boot up again.
3 Skip the network connection of the boot wizard (Fxxk GFW)
After swiping Gapps and entering the boot wizard, it seems that there is still no option to skip the step of connecting to the network. The solution is as follows: first unplug the SIM card, and then select the network interface to the left and right of the four corners of a pass, you can skip. Then it successfully enters the main interface, and the swiping machine is completed.

Reproduced in: https://www.cnblogs.com/psklf/p/6956343.html

ADB connection error

ADB Connection Error
There are times when you run into an ADB Connection Error when debugging real machines, which means that the port you are debugging is occupied.
The error reporting code for the problem I encountered is as follows:
Unable to create Debug Bridge; Unable to start adb server; error; cannot parse version string ; Kg01 ‘C: \ users \ \ * * * * * * * * adb. Exe, start – server’ failed – run manually if necessary.

here is my error report picture:

Solutions:
The error message indicates that the port is occupied by an adb.exe. Then we’ll find the adb.exe file in the cool dog folder and delete it. Does not affect the use of cool dog music.
Later, I summarized other problems that occupied the port, such as the following error code:
Unable to create Debug Bridge: Unable to start ADB Server: Error: could not install * SmartSocket * Listener: cannot bind to 127.0.0.1:5037
Could not read the ok from the ADB Server
* failed to start the daemon *
error: always connect to the daemon
‘D: * * * * * \ ADB exe, start – Server’ failed – run manually if necessary
This solution is different from the previous one:
Find the corresponding pid number occupying the port number 5037 by netstat -aon|findstr “5037”. Open task manager and kill the process with the corresponding PID number. Restart ADB.
 

Error 2738. Could not access VBScript run time for custom action.

This error literally means that the VBScript runtime cannot be accessed. This error is common during the installation or uninstallation of various applications under Windows.
The installation/uninstallation of some applications USES VBScript as a procedure script, and the operation of VBScript depends on its runtime environment.
The solution is simple:
1. Make sure you have vbscript.DLL on your machine.
If so, skip this step. If not, you can make a copy from another Windows system that has the same version installed.
For 64-bit Windows, vbscript.dll appears in two paths, namely:
c:\windows\system32\
c:\windows\syswow64\
What’s missing, what’s missing.
2. Manually register vbscript.DLL components in the console using the regSVR32 command.
After entering, a window will pop up saying “DllRegisterServer has succeeded in vbscript.dll”, indicating that the registration was successful.
Basically, at this point, this error will be resolved.
Similarly, Error 2739 (meaning that the JavaScript runtime cannot be accessed, which corresponds to a jscript.dll file) can also be handled in this way.
There are also articles on the web where the solution is to start with a registry, to look up a particular registry key and include some risky actions such as deletion. The personal understanding is to determine whether the relevant components have been registered correctly. For general users, the individual does not recommend this approach, may not solve the problem, but also introduce other troubles.
It is important to note that many applications to install/uninstall program when encounter this problem, only gives an error code, or add a such as “internal error”, make people confused about the prefix, it is the mistake of Windows, but to mislead the user thought is to install/uninstall the program itself.

Google payment error prompt: error retrieving information from server [df-aa-20]

Google in-purchase payment test, released the beta version for testing, download and install after payment error prompt: error when retrieving information from the server [df-aa-20]
The reasons may be:
1. This product does not create in-purchase goods. (It takes time for the creation to take effect, so you can wait 10 minutes to try again)
2. The app was not released in the Google Play store, at least in alpha.
3. The app or developer account is blocked.
 

A JavaScript error occured in the main process

As shown in the figure, when opening A certain software, the occured error of
A JavaScript error occured in the main process
Uncaught Exception:
error: be Unable to find A valid app
at Object.< anonymous> (E: \ \ Program Files \ (x86)… \ resources \ electron asar \ browser \ init js: 121:
9 at the Object

Solution: Redownload the latest version of the program and install it.
 

This error may also indicate that the docker daemon is not running.

Running error reporting after installing Docker Toolbox:

$ docker ps
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.37/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

Run command:

$ docker-machine create box

Create a Docker image

$ docker-machine create box
Running pre-create checks...
Creating machine...
(box) Copying C:\Users\Administrator\.docker\machine\cache\boot2docker.iso to C:\Users\Administrator\.docker\machine\machines\box\boot2docker.iso...
(box) Creating VirtualBox VM...
(box) Creating SSH key...
(box) Starting the VM...
(box) Check network to re-create if needed...
(box) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(box) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #3"
(box) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(box) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(box) Waiting for an IP...

Detailed installation procedures for Docker Toolbox refer to the official documentation:
https://docs.docker.com/toolbox/toolbox_install_windows/

Solve the unmarshalling error: unexpected element (URI: “local:” name “). Expected elements are

Unmarshalling Error: unexpected Element (URI :””, local:”name”). Expected Elements are < {}arg0>
Solutions:
Call the WebService interface to Error Unmarshalling Error: unexpected Element (URI :””, local:”name”). Expected Elements are < {}arg0>
Reason is the server-side service interface parameters before add: http://www.yayihouse.com/yayishuwu/chapter/1788

Perfectly solve the error loading media: file could not be played error

Recently, I need to use JWplayer plugin to play videos. However, no matter which version or what kind of video I changed, it always prompts Error loading media: File could not be played incorrectly. I finally solved it after a lot of effort.
Solutions:
The IIS default configuration does not add an MP4 file, which results in opening an MP4 file 404.
Open the IIS manager, MIME type

Add, extension mp4, type Video/MP4

Click OK.
The problem is solved, the test address: http://118.190.82.102:8080/
JWplayer 6.1 resources (with logo) to download address: http://www.80cxy.com/Blog/ResourceView?arId=2018071309114468202coMrW
JWplayer resources (logo) 7.10 download address: http://www.80cxy.com/Blog/ResourceView?arId=201807130915499925eixTjy
The original link: http://www.80cxy.com/Blog/ArticleView?arId=201807130908379497ZfgWan

Solution to “Ruby / San check”

Baidu one found that everyone is an article to turn around, as follows:
The root of the problem is the lack of a necessary C++ library. If it is a CentOS system, run the following command to resolve:

    yum install glibc-headers

    yum install gcc-c++ 

In Ubuntu, run the following command:

   apt-get install build-essential 
 
   apt-get install g++

I checked my GCC carefully and found that it was installed, not this problem. When executing YUM Update, I found this line:

glibc-headers-2.12-1.80.el6.x86_64 has missing requires of kernel-headers

So I tried it

yum install  kernel-headers

Problem solving.