Я работаю над диссертацией и нуждаюсь в помощи. Одна часть моей диссертации заключается в том, что мне нужно создать игровой выбор, мой тип подключения - Bluetooth, клиент - телефон Android, а сервер - Java. Я использую JFileChooser для получения значений для массива, и мне нужно передать этот массив другому классу. Я пытался следовать этой должности http://www.dreaminco...ifferent-class/, но в моей программе я не могу показаться, чтобы получить это работает, вот мой код:Получить массив из другого класса
DemoJFileChooser (класс, который я получаю массив, который является путь [])
package com.luugiathuy.apps.remotebluetooth;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DemoJFileChooser extends JPanel implements ActionListener {
JButton go;
JFileChooser chooser;
String choosertitle;
public int x=0;
public String path[] = new String[10];
public DemoJFileChooser() {
go = new JButton("Do it");
go.addActionListener(this);
add(go);
}
public Dimension getPreferredSize(){
return new Dimension(200, 200);
}
public static void main(String s[]) {
Thread waitThread = new Thread(new WaitThread());
waitThread.start();
JFrame frame = new JFrame("");
DemoJFileChooser panel = new DemoJFileChooser();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
frame.getContentPane().add(panel,"Center");
frame.setSize(panel.getPreferredSize());
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int result;
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
//
// disable the "All files" option.
//
chooser.setAcceptAllFileFilterUsed(false);
//
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): "
+ chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "
+ chooser.getSelectedFile());
File paths = chooser.getSelectedFile();
path[x] = paths.getAbsoluteFile().toString();
x++;
for (int y=0;y<9;y++){
System.out.println(path[y]);
setArray(path);
}
}
else {
System.out.println("No Selection ");
}
}
void setArray(String paths[]) { // saves surname to variable
path= paths;
}
String[] getArray() { //gets the surname when called
return path;
}
}
ProcessConnectionThread (класс, с помощью которого мне нужен массив)
package com.luugiathuy.apps.remotebluetooth;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.InputStream;
import java.io.OutputStream;
import com.luugiathuy.apps.remotebluetooth.DemoJFileChooser;
import javax.microedition.io.StreamConnection;
public class ProcessConnectionThread implements Runnable{
//DemoJFileChooser path;
//public String[] path = new String[10];
private StreamConnection mConnection;
// Constant that indicate command from devices
//private static final int EXIT_CMD = -1;
private static final int STEER_RIGHT = 1;
private static final int STEER_LEFT = 2;
private static final int ACCE = 3;
private static final int REV = 4;
private static final int MOVE = 5;
private static final int LEFT_CLICK = 6;
private static final int DOUBLE_CLICK = 7;
private static final int RIGHT_CLICK = 8;
private static final int HOLD = 9;
private static final int RELEASE = 10;
private static final int MOVEX = 11;
private static final int MOVEY = 12;
private static final int GAME = 20;
private static final int GAME1 = 11;
private static final int GAME2 = 12;
private static final int GAME3 = 13;
private static final int GAME4 = 14;
private static final int GAME5 = 15;
private DemoJFileChooser patharray[] = new DemoJFileChooser[10]; //create object array from student class
public ProcessConnectionThread(StreamConnection connection)
{
mConnection = connection;
}
public void FileChooser() { //constructor use keyword public just to make sure it is visible
for (int studI=0;studI<10;studI++) {
patharray[studI] = new DemoJFileChooser();
}
}
@Override
public void run() {
try {
// prepare to receive data
InputStream inputStream = mConnection.openInputStream();
OutputStream outputStream = mConnection.openOutputStream();
System.out.println("waiting for input");
while (true) {
int command = inputStream.read();
System.out.println(command);
processCommand(command);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Process the command from client
* @param command the command code
*/
private void processCommand(int command) {
try {
case GAME1:
for (int y=0;y<10;y++){
patharray[y].getArray();
System.out.println(patharray[y]);
}
Process p = Runtime.getRuntime().exec(patharray[0]);
p.waitFor();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Я встречая ошибку на цикл, patharray [].
любая помощь/предложения будут очень признательны. Спасибо.
Что говорит об ошибке? – Mahesh
http://i630.photobucket.com/albums/uu26/damnjeka/error.jpg –