当我从Codename One HelloWorld教程运行Codename One HelloWorld Java程序时,出现错误。

huangapple go评论69阅读模式
英文:

When I run the Codename One HelloWorld Java Program from the Codename One HelloWorld Tutorial, I get an error

问题

以下是翻译好的内容:

当我从Codename One HelloWorld教程视频中运行Codename One HelloWorld Java程序时,我会得到以下错误:
java: 找不到符号
符号: 类 Button
位置: 类 com.acmecorp.appname.AppName

我认为我缺少类Button的导入。如何为类Button添加导入语句,以便编译不会出现此错误?

这是我的源代码:

package com.acmecorp.appname;


import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;

/**
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose 
 * of building native mobile applications using Java.
 */
public class AppName {

    private Form current;
    private Resources theme;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if(err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });        
    }
    
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        Form hi = new Form("Hi World", BoxLayout.y());
        hi.add(new Label("Hi World"));
        Button b = new Button("Show Dialog");
        hi.add(b);
        b.addActionListener((e) -> Dialog.show("Dialog Title", "Hi", "OK", null));
        hi.show();
    }

    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }
    
    public void destroy() {
    }

}
英文:

When I run the Codename One HelloWorld Java Program from the Codename One HelloWorld Tutorial video, I get this error:
java: cannot find symbol
symbol: class Button
location: class com.acmecorp.appname.AppName

I think I'm missing an import for class Button. How do I add the import statement for class Button so that the compilation won't have this error?

Here is my source code:

package com.acmecorp.appname;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
/**
* This file was generated by &lt;a href=&quot;https://www.codenameone.com/&quot;&gt;Codename One&lt;/a&gt; for the purpose 
* of building native mobile applications using Java.
*/
public class AppName {
private Form current;
private Resources theme;
public void init(Object context) {
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme(&quot;/theme&quot;);
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
addNetworkErrorListener(err -&gt; {
// prevent the event from propagating
err.consume();
if(err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show(&quot;Connection Error&quot;, &quot;There was a networking error in the connection to &quot; + err.getConnectionRequest().getUrl(), &quot;OK&quot;, null);
});        
}
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form(&quot;Hi World&quot;, BoxLayout.y());
hi.add(new Label(&quot;Hi World&quot;));
Button b = new Button(&quot;Show Dialog&quot;);
hi.add(b);
b.addActionListener((e) -&gt; Dialog.show(&quot;Dialog Title&quot;, &quot;Hi&quot;, &quot;OK&quot;, null));
hi.show();
}
public void stop() {
current = getCurrentForm();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}

答案1

得分: 1

我猜这个 com.codename1.ui.Button 对你可能有用。

英文:

I guess this com.codename1.ui.Button might works for u.

huangapple
  • 本文由 发表于 2020年9月20日 17:42:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63977548.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定