eclipse出错:本地变量可能尚未初始化

时间:2016-03-24 01:46:04

标签: java eclipse

所以我用Java编写了一些简单的代码:

import java.util.Scanner;

declare @Profile table
    (
     id int identity(1, 1)
            primary key
            not null,
     City nvarchar(20)
    )

insert  into @Profile
values  (N'Chicago'),
        (N'Miami'),
        (N'Detroit')

declare @State table
    (
     id int identity(1, 1)
            primary key
            not null,
     State nvarchar(20),
     Population nvarchar(10)
    )

insert  into @State
values  (N'Illinois', N'10MM'),
        (N'Florida', N'20MM'),
        (N'Michigan', N'5MM'),
        (N'Virginia', N'7MM'),
        (N'Louisiana', N'3MM')

select  a.id,
        a.City,
        b.State
from    @Profile a
join    @State as b
on      a.id = b.id

在第10行,我收到错误:

public class Book {
    public static void main(String[] args) {

        String title;
        String author;
        String pages;
        Scanner scan;
        String input = scan.nextLine();

        // Book #1
        // =1=

        Book anothermedium = new Book();


}}

有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

是。不要只是声明 scan初始化它。变化

Scanner scan;

类似

Scanner scan = new Scanner(System.in);