Importing UsbSerialPort, Hexdump, SerialInputOutputManager in Android Studio - java

I'm trying to use the 'mik3y/usb-serial-for-android' library in order to read a serial connection. When trying to use the example code, I get errors because of certain things that will not import.
Here are the import statements that I'm having issues with(I've replaced my name and project info with dummy data):
import com.mycompany.johnsmith.driver.UsbSerialPort;
import com.mycompany.johnsmith.util.HexDump;
import com.mycompany.johnsmith.util.SerialInputOutputManager;
I receive the error: Cannot resolve symbol 'driver' for the first import, and Cannot resolve symbol 'util' for the other two.
I've installed the library as a dependency and all of my other imports work fine, but I'm still not sure if the issue is because of the library.

Related

VS Code - The import "#####" cannot be resolved

So, i am running a java project which have many library that are available in the current working directory but VS code seems to not recognize these library and giving out error "The import ###### cannot be resolved" ex: The import org.apache.pdfbox.pdmodel.PDDocument cannot be resolved"
here is the image that might help you to know more about it
This is the package that i am working on :
Here the org/apache is the library contain the class file that are need to be imported and FileArrangement.java is the file having the import statements
Error i have been receiving
this is what VS code is been showing
i really need your help because i really don't have any idea how to correct this
I have checked other projects and they are also showing the same result although the import statements for java classes like . java.util.ArrayList doesn't show any kind of error and i have tried to clean java in VS code it also didn't work
i just need to correct this error of VS code to import the classes that i need
No error on java.util package
Putting the libraries in your current working directory does not work for Java, you need to add them to the classpath.
If you're using maven, that manages the classpath for you.
If not, you can manage it in VS Code by executing the Java: Configure Classpath command from the Command Palette (Ctrl+Shift+P).
You can add dependencies via Referenced libraries under the JAVA PROJECTS panel.
Or use java.project.referencedLibraries setting in settings.json.
For example:
"java.project.referencedLibraries": [
"library/**/*.jar",
"/home/username/lib/foo.jar"
]
Details can be found in configure-classpath and manage-dependencies.

Android Studio import com.google.android.vending.expansion.zipfile.ZipResourceFile; does not exist

I am trying to setup the apk expansion setup. I added the SampleDownloaderActivity.java but I am getting these errors once I rebuild the project
import com.google.android.vending.expansion.zipfile.ZipResourceFile; does not exist
import com.google.android.vending.expansion.zipfile.ZipResourceFile.ZipEntryRO; does not exist
What is the alternative to correct this?
you have to include the expansion library separately as the code dependency, you can get the relevant code at location <sdk>/extras/google/google_market_apk_expansion/zip_file/

How to Import MQTT Paho into Java 'playground'?

GOAL: Java to publish an MQTT message through a code playground console. The playground is used to prove out functionality before transplanting instructions to Android Studio.
Reproduce the Error Message in the Playground
After clicking the link to the code playground, click the 'run' button to reproduce the error.
Error Messages
Why does adding the import statements in the code playground?:
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
cause a failure:
./Playground/Playground.java:4: error: package org.eclipse.paho.client.mqttv3 does not exist
import org.eclipse.paho.client.mqttv3.MqttClient;
^
./Playground/Playground.java:5: error: package org.eclipse.paho.client.mqttv3 does not exist
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
^
./Playground/Playground.java:6: error: package org.eclipse.paho.client.mqttv3 does not exist
import org.eclipse.paho.client.mqttv3.MqttException;
^
./Playground/Playground.java:7: error: package org.eclipse.paho.client.mqttv3 does not exist
import org.eclipse.paho.client.mqttv3.MqttMessage;
^
./Playground/Playground.java:8: error: package org.eclipse.paho.client.mqttv3.persist does not exist
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
^
5 errors
QUESTIONS
Why is it that the resource can not be found?
How can the obstacle be overcome? (substitutes?)
tl;dr - this probably will never work
The Paho Java library is not included with the default classes in the Java SDK. It is what is known as a third-party library.
It ships as a jar file that you need to add to the classpath of any Java runtime you want to use it with.
There are hundreds of thousands such libraries, each offering different extra functionality that extends the default set of standard classes and also available in different release versions.
There is no way the administrators of the code playground could know in advance which of those libraries a user might want to try and just including an import statement at the top of the class doesn't fully identify which version of the library you mean.
While systems like Maven provide a way to look up and download some these libraries in a standard way it's still not suitable for this type of environment and doesn't cover every library you might want.
Also even if the playground did have a way to specify third-party libraries this would open up a huge security problem, because they would have no control over the code that would now run on their machines. I expect the snippets are already run under a security manager that prevents access to the internet and local file system. This would prevent you from being able to connect to the broker.

I want to use jersey client in my code I have imported the packages still it shows error

I want to use jersey client in my code. I have imported the packages still and it shows an error.
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
I am using JDev environment.
Despite that when I run my code it throws:
Error(3,33): package com.sun.jersey.api.client does not exist
import com.sun.jersey.api.client.WebResource;
Any suggestion why is it throwing the error ?
first of all you have to download the library e.g. from here. Afterwards you can follow this tutorial to add the library to your project. Jersey depends also on other libraries (included in the bundle), so make sure to add them as well.

Java library import difficulty

I'm trying to compile a small test program I have written for a raspberry pi.
The program makes use of the Pi4J library to control the piface add-on board.
What I have done so far is based on the following tutorial: http://www.savagehomeautomation.com/piface
While I can get the above example program to compile within my IDE after setting up the class paths I get compile errors with the one I have made and as far as I can tell the imports are set up in the same way.
It says that each of the following packages does not exist:
import java.io.IOException;
import com.pi4j.component.switches.SwitchListener;
import com.pi4j.component.switches.SwitchState;
import com.pi4j.component.switches.SwitchStateChangeEvent;
import com.pi4j.device.piface.PiFace;
import com.pi4j.device.piface.PiFaceLed;
import com.pi4j.device.piface.PiFaceRelay;
import com.pi4j.device.piface.PiFaceSwitch;
import com.pi4j.device.piface.impl.PiFaceDevice;
import com.pi4j.wiringpi.Spi;
I'm assuming that my problem is relatively simple but I don't really understand how import statements work and it's quite vague topic to search about. I have included some file paths if that helps.
This is where my project resides:
/home/pi/JBerries/relay
and this is where the pi4j library is:
/opt/pi4j
I hope the following image provides some of the information requested, note that the class paths are already set up:
You need to set the CLASSPATH environment variable to /opt/pi4j or the jar file therein. WIthout this the compiler is unable to know where your libary is located and will give you the errors you describe.
If you're using a project in JBerries you need to configure the classpath for the project - the screenshot shows the classpath for single-file compilations only. To edit the project config right-click the root node in the project window and select properties.

Categories

Resources