JAVA控制台错误

时间:2017-03-29 23:15:36

标签: java netbeans

如果我在Netbeans中运行以下代码

import java.io.Console;
public class Introduction {        
    public static void main(String[] args) {
        Console console= System.console();// creates a java Object which has method that allows us to write
        console.printf("Hallo parvel");
    }        
} 

它给了我错误:

Exception in thread "main" java.lang.NullPointerException
    at Introduction.main(Introduction.java:10)
/home/parvel/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds). 

请帮助

2 个答案:

答案 0 :(得分:0)

module Acc where open import Data.Nat hiding (_≟_; _+_; _≤_) open import Data.Integer hiding (_≟_; suc) open import Data.String open import Data.Product open import Relation.Nullary open import Relation.Nullary.Decidable open import Relation.Binary.PropositionalEquality -- Trivial example of an EDSL inspired by -- http://www.lpenz.org/articles/hedsl-sharedexpenses/ -- We have n people who go on a trip -- they pay for things -- they give each other money -- at the end we want to have the balance on each account -- Syntax infixr 10 _•_ infixr 10 _and_ infix 20 _⇒_ data Person : Set where P : String → Person data Exp : Set where _⇒_ : Person → ℕ → Exp _[_]⇒_ : Person → ℕ → Person → Exp _and_ : Exp → Exp → Exp data Accounts : Set where □ : Accounts _,_ : (String × ℤ) → Accounts → Accounts data _∈ᵣ_ : (String × ℤ) → Accounts → Set where hereᵣ : ∀ {ρ s v} → (s , v) ∈ᵣ ((s , v) , ρ) skipᵣ : ∀ {ρ s v s' v'} → {α : False (s ≟ s')} → (s , v) ∈ᵣ ρ → (s , v) ∈ᵣ ((s' , v') , ρ) update : Accounts → String → ℤ → Accounts update □ s amount = (s , amount) , □ update ((s₁ , amount₁) , accounts) s₂ amount₂ with (s₁ ≟ s₂) ... | yes _ = (s₁ , (amount₁ + amount₂)) , accounts ... | no _ = (s₁ , amount₁) , update accounts s₂ amount₂ data account : Exp → Accounts → Accounts → Set where spend : ∀ {s n σ} → account (P s ⇒ (suc n)) σ (update σ s -[1+ n ]) give : ∀ {s₁ s₂ n σ} → account (P s₁ [ suc n ]⇒ P s₂) σ (update (update σ s₁ -[1+ n ]) s₂ (+ (suc n))) _•_ : ∀ {e₁ e₂ σ₁ σ₂ σ₃} → account e₁ σ₁ σ₂ → account e₂ σ₂ σ₃ → account (e₁ and e₂) σ₁ σ₃ andComm : ∀ {σ σ' σ'' e₁ e₂} → account (e₁ and e₂) σ σ' → account (e₂ and e₁) σ σ'' → σ' ≡ σ'' andComm (a₁ • a) (b • b₁) = {!!} 对象为null,因为没有连接控制台。

尝试从命令行或连接的控制台运行它。

在此处查找有关它的更多详细信息:https://netbeans.org/bugzilla/show_bug.cgi?id=111337

答案 1 :(得分:0)

您需要使用java -jar myjar.jar

从终端运行此命令

为了使用System.console();

将此打印输出到控制台

您需要将其导出为可运行的jar

然后你可以运行java -jar myjar.jar并输出Hallo parvel

相关问题