Having a problem with this code have been at it for quite a bit and have looked and played with it on multiple different occasions and angels and can't seem to get it going its not accepting the File underlined in red (Code Below) This belongs to the Dropbox Api the method in which Im trying to create is to upload a clients file to the dropBox... Im using a JFileChooser to open the file then putting it into a selected File and than a fileInputStream and this is where the problem is arising no matter which way I try and work around it, ints not budging. I have never worked with this API before but have looked at a lot of different exp. code and stilll can't seem to get it even after looking at their code?
package daword;
import java.util.ArrayList;
import java.awt.Desktop;
import java.io.File;
import com.dropbox.core.DbxAccountInfo;
import com.dropbox.core.*;
///import com.dropbox.core.DbxEntry.File;
import com.dropbox.core.json.JsonReader;
import com.dropbox.core.json.JsonReader.FileLoadException;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Locale;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.stage.FileChooser;
import javax.imageio.ImageIO;
import javax.naming.Context;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.DefaultEditorKit.CopyAction;
import javax.swing.text.DefaultEditorKit.CutAction;
public class dropBox extends JFrame implements ActionListener{
File inputFile;
private boolean logedIn = false;
JFileChooser fc;
String dirName;
final String APP_KEY = "00000";
final String APP_SECRET = "00000";
private JButton connect, upload;
ImageIcon im1;
DbxClient client;
JLabel jlab;
JPanel jpan;
ImageIcon login;
BorderLayout borderlayout;
JTextField field = new JTextField(15);
JPopupMenu menu = new JPopupMenu("Menu");
//boolean isAuthTokenReady = false;
InetSocketAddress add;
//boolean connection = false;
public JButton jb;
public dropBox(){
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(600,600);
setLocationRelativeTo(null);
setResizable(false);
setLookAndFeel();
JOptionPane.showMessageDialog(null,"1.Please Click Login\n2.Click Options\n3.Use How You Please!",
"Instructions", JOptionPane.WARNING_MESSAGE);
internet();
borderlayout = new BorderLayout();
getClipboard();
im1 = new ImageIcon(getClass().getResource("dropBox.gif"));
jlab= new JLabel(im1);
jlab.setLayout(null);
add(jlab);
login = new ImageIcon(getClass().getResource("login.gif"));
connect = new JButton( login);
connect.setSize(180, 57);
jlab.add(connect);
connect.addActionListener(this);
upload = new JButton ("upload");
upload.setBounds(0, 0, 220, 30);
upload.addActionListener(this);
jlab.add(upload);
BorderLayout bord = new BorderLayout();
setVisible(true);
}
public void internet (){
Socket sock = new Socket();
add = new InetSocketAddress("www.google.com", 80);
try{
wifi= true;
sock.connect(add, 3000);
System.out.println("Connection Present");
ImageIcon img = new ImageIcon("/images/wifi.png");
jb = new JButton(img);
} catch(IOException e){
System.out.println(" No Connection");
}
}
@Override
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
Object uploadS = evt.getSource();
if(source == connect){
try{
drop();
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Unable To Connect :( Please Try Again ..",
"ALERT", JOptionPane.WARNING_MESSAGE);
}
}else if(uploadS == upload){
if (logedIn = true){
try {
uploadFile();
} catch (DbxException ex) {
Logger.getLogger(dropBox.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(dropBox.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void setLookAndFeel() {
try{
UIManager.setLookAndFeel("UIManager.getSystemLookAndFeelClassName");
}catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
UnsupportedLookAndFeelException e){
}
}
public static String getClipboard() {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
// JButton Login
public void drop() throws IOException, DbxException{
String userLocale = Locale.getDefault().toString();
DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
DbxRequestConfig config = new DbxRequestConfig("Daword",
Locale.getDefault().toString());
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
// Have the user sign in and authorize your app.
String authorizeUrl = webAuth.start();
System.out.println("You Will Be Redirected To: " + authorizeUrl);
JOptionPane.showMessageDialog(null,"Go To:"+ authorizeUrl,
"" +
"", JOptionPane.WARNING_MESSAGE);
java.awt.Desktop.getDesktop().browse(java.net.URI.create(authorizeUrl));
System.out.println("Enter Your auth code in this prompt and hit enter and wait..");
String userA = JOptionPane.showInputDialog(null, "Enter your auth code here:"); //Prompt for
if (userA.isEmpty()) {
System.exit(1);
}
System.out.println(userA.trim()); //For testing purposes print the trimmed auth code to console.
// [Omitted Code] //
// This will fail if the user enters an invalid authorization code.
DbxAuthFinish authFinish = webAuth.finish(userA);
String accessToken = authFinish.accessToken;
client = new DbxClient(config, accessToken);
DbxAuthInfo authInfo = new DbxAuthInfo(authFinish.accessToken, appInfo.host);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
JOptionPane.showMessageDialog(null, "Welcome"+
client.getAccountInfo().displayName+ authFinish.accessToken+
" And Welcome To Our Community!");
}
public void uploadFile() throws FileNotFoundException, DbxException, IOException{
fc = new JFileChooser();
fc.setMultiSelectionEnabled(true);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int dialog = fc.showSaveDialog(this);
if (dialog == JFileChooser.APPROVE_OPTION) {
inputFile = fc.getSelectedFile().getAbsoluteFile();
try (FileInputStream inputStream = new FileInputStream(inputFile)) {
DbxEntry.File uploadedFile = client.uploadFile("",
DbxWriteMode.add(), inputFile.length(), inputStream);
String sharedUrl = client.createShareableUrl("");
System.out.println("Uploaded: " + uploadedFile.toString() + " URL " + sharedUrl);
}
}
}
}