Tag Archives: runtime error

Go run error go run: cannot run non main package

I was born in Java. Recently I became interested in go language, so I will learn it with go in the future.

After the go environment is installed and configured, the vscode development tool is installed, and the first go program is written. It’s very simple, just a simple output statement, but it does

Go run: cannot run non main package. The code is as follows:

package test
import "fmt"
func main() {
  fmt.Println("cainiaobulan testing go")
}

The error message of go is very straightforward. The main method can only be placed in package main. Go run is to execute the command and a main must be used to call it. Install can be directly compiled into a package file or an EXE (if there is a main function)

Change the code and run OK

package main
import "fmt"
func main() {
  fmt.Println("cainiaobulan testing go")
}

Just take this mistake as the first step for me to learn go. In the future, I can cross the pit step by step. I hope that children’s shoes with the same interest can learn together and carry forward go. At the same time, I also want to seek guidance from the boss. I am ready to develop in the direction of go web.

Runtime error prompt in Android Studio: arrayadapter requires the resource ID to be a textview problem

At first, listview uses Android’s own simple_ list_ item_1 display simple text. Use the default attribute, and the code is as follows:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, adapterData);
listView.setAdapter(adapter);

After that, when the function is updated, you need to change the font color of item and specify the typeface. Record is customized in RES/layout/folder_ text.xml File:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/TView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textColor="#2d373c"
        android:textSize="18sp"
        />
</LinearLayout>

Change the code in. Java file to:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(RecordActivity.this,
         R.layout.record_text, adapterData);
 listView.setAdapter(adapter);

 //Change the item display text to a custom font
 LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 View view = layoutInflater.inflate(R.layout.record_text, null);
 TextView w = (TextView)view.findViewById(R.id.TView);
 Typeface tfsisan03 = Typeface.createFromAsset(getAssets(), "fonts/sisan03_0.ttf");
 w.setTypeface (tfsisan03);

Run, error prompt: arrayadapter requires the resource ID to be a textview. Finally, we found the problem of. XML file. The root label must be textview and cannot nest LinearLayout. After modification, the error will be resolved.

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TView"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:textColor="#2d373c"
    android:layout_marginLeft="10dp"
    android:paddingLeft="10dp"
    android:gravity="center_vertical"
    android:textSize="16sp"
    />

 

Cause of runtime error on OJ

Except for the five cliches
1. Array size is too small, resulting in access to the memory should not be accessed
2. A division by zero error occurred
3. A large array is defined inside a function, causing the program stack to run out
4, The pointer is used incorrectly, resulting in access to the memory should not be accessed
5. It is also possible that the program threw an unreceived exception
The author also found that sometimes open array on OJ is too large (global variables, can run normally in the local) will cause runtime error, we need to pay attention to.

Pychar runtime error r6034 solution

After Updating PyCharm, open a program, set the Project Interpreter and the software starts Updating Python Interpreter. It had run smoothly before, but this time it got stuck:

Simultaneously report an error:

 
Found a solution to this problem on Stack Overflow, so share it here. Click here for the original.
Step1: download Process Explorer and open procexp.exe inside.
Step2: select view-& gt from the menu of software interface; lower pane view -> Then find the Python. exe under the Pycharm directory and click, and the bottom pane should display a list of DLLs loaded for the application.

Step3: find “MSVCR??” in the DLL list. .DLL “, pay attention to the following path, as long as it is not under the path of “C:\Windows\WinSxS”, it should be deleted or renamed the suffix. For example, in the figure above, there is a MSvCR90. DLL under D:\Anaconda3\envs\ Python27 \msvcr90. DLL. Find it and rename it “MSvCR90. DLL -bak”.
Step4: restart pycharm and it will be ok.

After the go pointer is declared and assigned, a panic: runtime error: invalid memory address or nil pointer reference appears

pointer basics
package main

import "fmt"

func main() {
	var p *int
	p = new(int)
	*p = 1
	fmt.Println(p, &p, *p)
}

Output
0xc04204a080  0xc042068018  1

Go * represents the value stored in the pointer address, & is the address to take a value. For the pointer, it’s important to understand that the pointer stores the address of a value, but the pointer itself also needs the address to store
As above p is a pointer whose value is memory address 0xc04204a080</code b> and p memory address 0xc042068018 memory address 0xc04204a080 memory address 0 11
The

error instance

In golang if we define a pointer and assign it to it like a normal variable, such as the code below

package main

import "fmt"
func main() {
	var i *int
	*i = 1
    fmt.Println(i, &i, *i)
}

Would have reported such an error

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x0 pc=0x498025]

The reason for this error is that go when you initialize the pointer it gives the pointer I and it gives the pointer nil, but I is the address of * I , 0 nil1 the system doesn’t give the address of 2 * I 3, So there’s definitely an error in assigning * I and it’s very easy to solve this problem, you can just create a block of memory to allocate to an assignment object before you assign to a pointer

package main

import "fmt"
func main() {
	var i *int
	i = new(int)
	*i = 1
	fmt.Println(i, &i, *i)
}