gpt4 book ai didi

java - 初始化类实例?

转载 作者:太空狗 更新时间:2023-10-29 15:34:06 27 4
gpt4 key购买 nike

我正在尝试使用 consoleDroid console = new consoleDroid(); 初始化类 consoleDroid 的实例,但它抛出一个 类、接口(interface)或预期枚举 编译错误。初始化类的正确方法是什么?

caseSelector.java:

package com.caseselector;

import android.app.Activity;
import android.os.Bundle;

consoleDroid console = new consoleDroid();

public class caseSelector extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

console.create();
}
}

consoleDroid.java:

package com.caseselector;

import android.view.View;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Button;

public class consoleDroid {

private static String output;
private Button consoleButton;
private TextView consoleView;
private EditText consoleInput;

public static void create() {
}

public static void write(String input) {
}

public static void writeLine(String input) {
}

public static String readLine(boolean print) {
return output;
}
}

最佳答案

只需将您的实例化向下移动到类主体中:

public class caseSelector extends Activity
{
consoleDroid console = new consoleDroid();
// ...
}

顺便说一句:按照惯例,类名应该以大写字母开头。

关于java - 初始化类实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3806177/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com