Error when trying to upload

Hey!
Every time I try to upload, the following error appears:

"avrdude: ser_open(): can't open device "\.\COM3": Access is denied.

Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
An error occurred while uploading the sketch"

I have Windows 10 and a NanoATMega 328 chip. I have verified the USB port is correct and the correct board has been selected. I did a code check and it was also correct.

Code:
void setup() {
// put your setup code here, to run once:
digitalWrite(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite(13,255);
analogWrite(13,127);
analogWrite(13,10);
}

How should I fix it?
Thank you!

The "Access is denied" error happens when the port is open in another application. Make sure you don't have any other applications running that might have the port open. If you can't find any, try restarting your computer. Sometimes a glitch causes the port to get stuck open and restarting fixes that.

Thanks for replying. I restarted the computer and opened solely the Arduino software. I still get the same error, but sometimes I get the following error as well with the previous one stated:

"An error occurred while uploading the sketch
avrdude: ser_open(): can't open device "\.\COM3": Access is denied.

Exception in thread "Thread-20" java.lang.NullPointerException
at cc.arduino.contributions.libraries.LibrariesIndexer.lambda$rescanLibraries$2(LibrariesIndexer.java:165)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
at java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1235)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at cc.arduino.contributions.libraries.LibrariesIndexer.rescanLibraries(LibrariesIndexer.java:167)
at cc.arduino.contributions.libraries.LibrariesIndexer.setLibrariesFolders(LibrariesIndexer.java:120)
at processing.app.BaseNoGui.onBoardOrPortChange(BaseNoGui.java:677)
at processing.app.Base.onBoardOrPortChange(Base.java:1333)
at processing.app.Editor$UploadHandler.run(Editor.java:2111)
at java.lang.Thread.run(Thread.java:748)"

Thank you for your time.