Я пишу программу для подключения к эскизу примера пикселя консоли с помощью java. Im все еще Prety новое, и я получил эту ошибку:Нестационарная переменная не может ссылаться на статический контекст java
non-static variable fast cannot be referenced from a static context
Я не знаю, что значит ошибка, но мой код:
package javaapplication5;
import java.net.*;
import java.io.*;
import java.util.Scanner;
/**
*
* @author preferreduser
*/
public class JavaApplication5 {
int fast = 0;
public static void main(String[] args) throws IOException {
Scanner x = new Scanner(System.in);
System.out.print("Yun ip: ");
String IP = x.nextLine();
System.out.println("Loding...");
try {
// Create a URL for the desired page
URL url = new URL("http://"+ IP +"/arduino/digital/13/1");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
try {
// Create a URL for the desired page
URL url = new URL("http://"+ IP +"/arduino/digital/13/0");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
System.out.println("Connected to YUN on "+ IP);
OUTER:
while (true) {
Scanner y = new Scanner(System.in);
System.out.print("> ");
String str = y.nextLine();
switch (str) {
case "on":
try {
// Create a URL for the desired page
URL url = new URL("http://"+ IP +"/arduino/digital/13/1");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
} break;
case "off":
try {
// Create a URL for the desired page
URL url = new URL("http://"+ IP +"/arduino/digital/13/0");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
} break;
case "help":
System.out.println("");
System.out.println("on exit");
System.out.println("off help");
System.out.println("");
break;
case "exit":
try {
// Create a URL for the desired page
URL url = new URL("http://"+ IP +"/arduino/digital/13/0");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
} break OUTER;
}
if (fast == 1){
URL oracle = new URL("http://"+ IP +"/arduino/digital/13");
try (BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()))) {
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
}
} else {System.out.println("Success");}
}
}
}
Я хочу подключить к Arduino Юна и команды, как тип включен или выключен, и эта часть работала. Я хотел бы добавить опциональную опцию быстро, чтобы исключить подключение к http: // */aruino/digital/13 каждый раз, когда вы ввели команду, чтобы ускорить работу. Это было мое начало. Я собираюсь добавить команду для нее, но я не могу, пока не получу это.
[Здесь] (http://stackoverflow.com/questions/2559527/non-static-variable-cannot-be-referenced-from-a-static-context), [здесь] (http: // stackoverflow. com/questions/15331846/non-static-variable-this-can-not-referenced-from-a-static-context) и [здесь] (http://stackoverflow.com/questions/15962339/non-static-variable это не может быть ссылкой-из-статического-контекста) среди нескольких. Перед отправкой вопроса, пожалуйста, зайдите в свой вопрос. – Mena
Прежде всего, попробуйте немного прояснить свой код; кроме проблем с форматированием, есть фрагменты кода, которые вы можете разделить на несколько методов. – fge
Не оставляйте пустые секции выреза. По крайней мере, напечатайте стек. – Pshemo