Connecting to XMPP server from android - java

The same code is working if I run the class from eclipse as a java application but when I am using same class in android studio I am getting the following RuntimeException.
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/security/sasl/Sasl;
The log :
FATAL EXCEPTION: Thread-62267
Process: com.abcd.abcd, PID: 14825
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/security/sasl/Sasl;
at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:92)
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:319)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203)
at com.abcd.abcd.XmppManager.login(XmppManager.java:99)
at com.abcd.abcd.Main.initializeXmppConnection(Main.java:78)
at com.abcd.abcd.Main.init(Main.java:72)
at com.abcd.abcd.Main.<init>(Main.java:61)
at com.abcd.abcd.MainActivity$1.run(MainActivity.java:32)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.security.sasl.Sasl" on path: DexPathList[[zip file "/data/app/com.abcd.abcd-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:92) 
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:319) 
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203) 
at com.abcd.abcd.XmppManager.login(XmppManager.java:99) 
at com.abcd.abcd.Main.initializeXmppConnection(Main.java:78) 
at com.abcd.abcd.Main.init(Main.java:72) 
at com.abcd.abcd.Main.<init>(Main.java:61) 
at com.abcd.abcd.MainActivity$1.run(MainActivity.java:32) 
at java.lang.Thread.run(Thread.java:818) 
Suppressed: java.lang.ClassNotFoundException: javax.security.sasl.Sasl
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 10 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I am stuck here and really not getting what the problem is. Any help guys?

hi if you want to update your library for studio that is one option is good but if you want to use same code in studio as well then you can visit this code here and check if you are doing correct or not.Some problem with ssl permission check here correct way
private XMPPConnection connect() throws XMPPException, SmackException,
IOException {
if ((this.connection != null) && (this.connection.isConnected())) {
return this.connection;
}
ConnectionConfiguration config = new ConnectionConfiguration(HOST1,
5222);
SmackConfiguration.DEBUG_ENABLED = true;
SASLAuthentication.supportSASLMechanism("MD5", 0);
System.setProperty("smack.debugEnabled", "true");
config.setCompressionEnabled(false);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setReconnectionAllowed(true);
config.setSendPresence(true);
config.setRosterLoadedAtLogin(true);
if (Build.VERSION.SDK_INT >= 14) {
config.setKeystoreType("AndroidCAStore");
config.setKeystorePath(null);
} else {
config.setKeystoreType("BKS");
String str = System.getProperty("javax.net.ssl.trustStore");
if (str == null) {
str = System.getProperty("java.home") + File.separator + "etc"
+ File.separator + "security" + File.separator
+ "cacerts.bks";
}
config.setKeystorePath(str);
}
if (connection == null) {
this.connection = new XMPPTCPConnection(config);
}
this.connection.connect();
Roster roster = connection.getRoster();
roster.addRosterListener(new RosterListener() {
#Override
public void presenceChanged(Presence arg0) {
Log.d("deb", "ug");
}
#Override
public void entriesUpdated(Collection<String> arg0) {
Log.d("deb", "ug");
}
#Override
public void entriesDeleted(Collection<String> arg0) {
Log.d("deb", "ug");
}
#Override
public void entriesAdded(Collection<String> arg0) {
Log.d("deb", "ug");
}
});
return this.connection;
}
Thankyou
Hope this will help you.

Android runtime does not have javax.security.sasl package, upgrade your Smack library, there is a custom SASL implementation for android

Probably you should upgrade your library or compile your gradle.
For some informations: What is Gradle in Android Studio?

Related

why the error occurs Didn't find class "java.lang.ClassValue"?

i use jython-standalone-2.7.2.jar in my application...
compiler is Android Studio 2020 3.1...
minSdk 26 in build.gradle.
An error occurs on the line
PythonInterpreter interp = new PythonInterpreter();
Code:
import org.python.util.PythonInterpreter;
import org.python.core.*;
public class SimpleEmbedded {
public static void main(String []args) throws PyException {
[PythonInterpreter interp = new PythonInterpreter();][1]
/// System.out.println("Hello, world from Java");
// interp.execfile("hello.py");
/// interp.set("a", new PyInteger(42));
// interp.exec("print a");
// interp.exec("x = 2+2");
// PyObject x = interp.get("x");
// System.out.println("x: "+x);
System.out.println("Goodbye ");
}
}
Error:
2021-09-29 21:19:12.368 3202-3202/com.serg.myjython E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.serg.myjython, PID: 3202
**java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/ClassValue**;
at org.python.core.PyType.fromClass(PyType.java:2137)
...
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: **java.lang.ClassNotFoundException: Didn't find class "java.lang.ClassValue"** on path: DexPathList[[zip file "/data/app/~~VsbgLG28nD-Vw7dAU-vIyA==/com.serg.myjython-ODUx9HepPkKuKHI_uTVWdw==/base.apk"],nativeLibraryDirectories=[/data/app/~~VsbgLG28nD-Vw7dAU-vIyA==/com.serg.myjython-ODUx9HepPkKuKHI_uTVWdw==/lib/x86, /system/lib, /system_ext/lib]]
Because the android jdk (built into the phone) does not have the class java.lang.ClassValue. You should copy the class from the open JDK or Oracle JDK, and fix the unable called APIs.

Error connecting Android Studio app to remote MySQL: java.sql.SQLNonTransientConnectionException: Could not create connection to database server

I'm trying to connect an Android Studio app to a remote MYSQL database but an error is displaying that couldn't create a connection to the database.
Some troubleshooting I did:
Reviewed if the database is running (it is)
Connected from MySQL workbench in my computer to the remote database (I was able to connect and retrieve data)
Also I was developing another app (no Android Studio). I used the same connection classes and I was able to access the data.
--- With this, I think that is not a server issue. ---
Used different JDBC drivers (Gradle implementation below of the versions I used)
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.23'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'
I also tried to add the .jar file in the project files but had other errors that didn't recognized the driver.
--- With this, I noticed that implementing the driver in Gradle is not an error as apparently it is recognizing the driver ---
Note: I'm currently using the gradle implementation.
I added the internet permissions to the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
I tried to implement the code that retrieves the data from the data base using an ASYNCTASK but received the following errors
Main class WITH ASYNCTASK (MainActivity.java)*
Note: The code in this class was just to test if I was able to get the data from the database. Is not regarding to any functionality I was trying to implement in the app itself.
public class MainActivity extends AppCompatActivity {
AlertDialog.Builder builder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Data");
new GetCultivos().execute();
builder.setPositiveButton("Accept", null);
AlertDialog dialog = builder.create();
dialog.show();
}
});
class GetCultivos extends AsyncTask<Void, Void, Void>{
String list = "Data = ";
#Override
protected Void doInBackground(Void... voids) {
CultivoDao cultivoDao = new CultivoDao();
List<Cultivo> listaCultivos = cultivoDao.obtenerCultivos();
for (Cultivo i : listaCultivos){
list = i.getIdCultivo() + " " + i.getNombre() + ", ";
}
return null;
}
#Override
protected void onPostExecute(Void eVoid){
builder.setMessage(list);
}
}
}
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.appmov, PID: 5699
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:399)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/SQLType;
at com.mysql.cj.jdbc.DatabaseMetaData.getInstance(DatabaseMetaData.java:729)
at com.mysql.cj.jdbc.ConnectionImpl.getMetaData(ConnectionImpl.java:1180)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:446)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at java.sql.DriverManager.getConnection(DriverManager.java:580)
at java.sql.DriverManager.getConnection(DriverManager.java:218)
at com.DAO.appmov.CultivoDao.StartConnection(CultivoDao.java:30)
at com.DAO.appmov.CultivoDao.obtenerCultivos(CultivoDao.java:49)
at com.example.appmov.MainActivity$GetCultivos.doInBackground(MainActivity.java:228)
at com.example.appmov.MainActivity$GetCultivos.doInBackground(MainActivity.java:220)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:919) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.sql.SQLType" on path: DexPathList[[zip file "/data/app/com.example.appmov-U33MrmDYU8kMl3MFpFCdcA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.appmov-U33MrmDYU8kMl3MFpFCdcA==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.mysql.cj.jdbc.DatabaseMetaData.getInstance(DatabaseMetaData.java:729) 
at com.mysql.cj.jdbc.ConnectionImpl.getMetaData(ConnectionImpl.java:1180) 
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:446) 
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) 
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207) 
at java.sql.DriverManager.getConnection(DriverManager.java:580) 
at java.sql.DriverManager.getConnection(DriverManager.java:218) 
at com.DAO.appmov.CultivoDao.StartConnection(CultivoDao.java:30) 
at com.DAO.appmov.CultivoDao.obtenerCultivos(CultivoDao.java:49) 
at com.example.appmov.MainActivity$GetCultivos.doInBackground(MainActivity.java:228) 
at com.example.appmov.MainActivity$GetCultivos.doInBackground(MainActivity.java:220) 
at android.os.AsyncTask$3.call(AsyncTask.java:378) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:919) 
I/Process: Sending signal. PID: 5699 SIG: 9
So I tried to implement the code without an ASYNCTASK, but I'm receiving the error that you can see below in the error log.
Class I use to connect to the database (CultivoDao.java)
public class CultivoDao {
private Connection connection;
private Statement statement;
//Method to start the connection
private void StartConnection() {
String url = "jdbc:mysql://remotemysql.com:3306/hUfMa4wLpe";
String usuario = ***HERE IS THE USERNAME***;
String password = ***HERE IS THE PASSWORD***;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(url, usuario, password);
statement = connection.createStatement();
} catch (Exception e) {
e.printStackTrace();
}
}
//Method to close the connection
private void CloseConnection(){
try {
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//Methog to get the data
public List<Cultivo> obtenerCultivos(){
List<Cultivo> listaCultivos = new ArrayList<>();
try {
StartConnection();
ResultSet rs = statement.executeQuery("Select * from cultivo");
while(rs.next()){
Cultivo cultivo = new Cultivo(rs.getInt("idCultivo"), rs.getString("nombre"));
listaCultivos.add(cultivo);
}
}catch (Exception e){
e.printStackTrace();
}
CloseConnection();
return listaCultivos;
}
}
Main class WITHOUT ASYNCTASK (MainActivity.java)*
Note: The code in this class was just to test if I was able to get the data from the database. Is not regarding to any functionality I was trying to implement in the app itself.
public class MainActivity extends AppCompatActivity {
AlertDialog.Builder builder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
builder = new AlertDialog.Builder(MainActivity.this);
String list = "Database list = ";
CultivoDao cultivoDao = new CultivoDao();
List<Cultivo> listaCultivos = cultivoDao.obtenerCultivos();
for (Cultivo i : listaCultivos){
list = i.getIdCultivo() + " " + i.getNombre() + ", ";
}
builder.setTitle("Data");
builder.setMessage(list);
builder.setPositiveButton("Accept", null);
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
}
The actual version I'm using is the one without the ASYNCTASK
I'm testing this app in a physical device. I don't know that this can affect in some way.
Error log:
W/System.err: java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
W/System.err: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1008)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at java.sql.DriverManager.getConnection(DriverManager.java:580)
at java.sql.DriverManager.getConnection(DriverManager.java:218)
at com.DAO.appmov.CultivoDao.StartConnection(CultivoDao.java:30)
at com.DAO.appmov.CultivoDao.obtenerCultivos(CultivoDao.java:49)
at com.example.appmov.MainActivity$1.onClick(MainActivity.java:88)
at android.view.View.performClick(View.java:7870)
at android.widget.TextView.performClick(TextView.java:14970)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:967)
at android.view.View.performClickInternal(View.java:7839)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29363)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
W/System.err: Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1565)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:115)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132)
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
at com.mysql.cj.NativeSession.connect(NativeSession.java:152)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
... 22 more
java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.ResultSet java.sql.Statement.executeQuery(java.lang.String)' on a null object reference
at com.DAO.appmov.CultivoDao.obtenerCultivos(CultivoDao.java:50)
at com.example.appmov.MainActivity$1.onClick(MainActivity.java:88)
at android.view.View.performClick(View.java:7870)
at android.widget.TextView.performClick(TextView.java:14970)
W/System.err: at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:967)
at android.view.View.performClickInternal(View.java:7839)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29363)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
java.lang.NullPointerException: Attempt to invoke interface method 'void java.sql.Connection.close()' on a null object reference
at com.DAO.appmov.CultivoDao.CloseConnection(CultivoDao.java:40)
at com.DAO.appmov.CultivoDao.obtenerCultivos(CultivoDao.java:58)
at com.example.appmov.MainActivity$1.onClick(MainActivity.java:88)
at android.view.View.performClick(View.java:7870)
at android.widget.TextView.performClick(TextView.java:14970)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:967)
at android.view.View.performClickInternal(View.java:7839)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29363)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
How can I solve this issue without implementing PHP that is another way I found as I can't edit anything of the server where the database is hosted.
Thanks!
ClassNotFoundException: Didn't find class "java.sql.SQLType"
Since java.sql.SQLType was added in Java 8, and doesn't exist at all on Android, you need to use a JDBC driver that is Java 7 compatible, which means you cannot use Connector/J 8.0, but must use version 5.1.

java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener

I want to work telegram API, I create Bot in telegram and set username and get a token but I can not connect with my java code please help me
I use this code
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
telegramBotsApi.registerBot(new TradeBot());
} catch (TelegramApiException e) {
e.printStackTrace();
}
and my proxy is set and test connection is right
public class TradeBot extends TelegramLongPollingBot {
public void onUpdateReceived(Update update) {
}
public String getBotUsername() {
return "xxx";
}
public String getBotToken() {
return "xxx";
}
}
and after run code give this error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/RemovalListener
at com.google.inject.internal.InheritingState.<init>(InheritingState.java:63)
at com.google.inject.internal.InjectorShell$Builder.getState(InjectorShell.java:208)
at com.google.inject.internal.InjectorShell$Builder.lock(InjectorShell.java:114)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:102)
at com.google.inject.Guice.createInjector(Guice.java:87)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at org.telegram.telegrambots.meta.ApiContext.getInjector(ApiContext.java:48)
at org.telegram.telegrambots.meta.ApiContext.getInstance(ApiContext.java:27)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.<init>(TelegramLongPollingBot.java:16)
at TradeBot.<init>(TradeBot.java:6)
at MainClass.main(MainClass.java:10)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.RemovalListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 12 more
Was answered here:
Google Guice can't find class
You need the correct version of the com.google.guava/guava dependency related to the com.google.inject/guice library that you are already using.

java.lang.NoClassDefFoundError: com/google/common/io/NullOutputStream

I have just started to learn NetApp SDK and trying to run the very first example created by NetApp. I am getting the following error and I don't have any idea why there is something related to com/google/common/io/NullOutputStream
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/NullOutputStream
at com.netapp.nmsdk.client.ApiTarget$Encoding$1.createApiInvocation(ApiTarget.java:202)
at com.netapp.nmsdk.client.ApiRunner.createApiInvocation(ApiRunner.java:153)
at com.netapp.nmsdk.client.ApiRunner.run(ApiRunner.java:131)
at com.netapp.nmsdk.client.ApiRunner.run(ApiRunner.java:105)
at getSystemMode.getSystemMode.main(getSystemMode.java:30)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.NullOutputStream
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
package getSystemMode;
import com.netapp.nmsdk.client.ApiRunner;
import com.netapp.nmsdk.client.ApiTarget;
import com.netapp.nmsdk.client.ApiTarget.TargetType;
import com.netapp.nmsdk.ontap.api.system.SystemGetVersionRequest;
import com.netapp.nmsdk.ontap.api.system.SystemGetVersionResponse;
public class getSystemMode {
public static void main(String[] args) {
if (args.length < 3) {
System.err.println("Usage: SystemMode <storage-system> <user> <passwd>");;
System.exit(1);
}
try {
ApiRunner runner = new ApiRunner(ApiTarget.builder()
.withHost(args[0])
.withUserName(args[1])
.withPassword(args[2])
.withTargetType(TargetType.FILER)
.useHttp()
.build());
SystemGetVersionRequest req = new SystemGetVersionRequest();
SystemGetVersionResponse resp = runner.run(req);
if (resp.isClustered() != null && resp.isClustered()) {
System.out.println("The storage system " + args[0] + " is in \"Cluster-Mode\"");
} else {
System.out.println("The storage system " + args[0] + " is in \"7-Mode\"");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
NullOutputStream removed from Guava 15.
Use ByteStreams.nullOutputStream() instead. This class is scheduled to be removed in Guava release 15.0.
You have to look your guava version.
More info;
Guava Version Problem About NullOutputStream

(Android) No Class Def Found Error for com.loopj.android.http.AsyncHttpClient

I've added the following (http://loopj.com/android-async-http/) to my /libs folder and have also put it in the module settings as a library and ticked the export button. In the actual file there are no errors given that it can't find the class and when I do import com.loopj and so-forth it completes it for me and shows me the available options.
However, when I run it on my phone it gives the following errors:
12-02 23:00:08.943 8209-8209/mobi.vassilev.beam E/dalvikvm﹕ Could not find class 'com.loopj.android.http.AsyncHttpClient', referenced from method mobi.vassilev.beam.GoogleLoginActivity.requestAPIKeyFromOAuthToken
12-02 23:00:09.183 8209-8209/mobi.vassilev.beam E/﹕ file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!
12-02 23:00:10.453 8382-8382/? E/ObjectHelper﹕ Can't find method:setCompatibilityInfo
12-02 23:00:10.598 8209-8209/mobi.vassilev.beam E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.loopj.android.http.AsyncHttpClient
at mobi.vassilev.beam.GoogleLoginActivity.requestAPIKeyFromOAuthToken(GoogleLoginActivity.java:118)
at mobi.vassilev.beam.GoogleLoginActivity.access$200(GoogleLoginActivity.java:24)
at mobi.vassilev.beam.GoogleLoginActivity$OnTokenAcquired.run(GoogleLoginActivity.java:105)
at android.accounts.AccountManager$11.run(AccountManager.java:1335)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
12-02 23:00:10.633 513-548/? E/EmbeddedLogger﹕ App crashed! Process: mobi.vassilev.beam
and the extract of code (not complete obv as the URL is fake, but that shouldn't affect anything):
private void requestAPIKeyFromOAuthToken(String token) {
AsyncHttpClient client = new AsyncHttpClient(); // <-- this is line 118
RequestParams params = new RequestParams("token", token);
client.post("https://myrailsapp.com/api/v1/auth/verify", params, new AsyncHttpResponseHandler() {
#Override
public void onSuccess(String response) {
Log.w("OAUTH", "Got API key from server: " + response);
finish();
}
#Override
public void onFailure(Throwable e) {
Log.w("OAUTH", "Error getting API key");
Toast.makeText(getApplicationContext(), R.string.connection_error_message, Toast.LENGTH_LONG).show();
e.printStackTrace();
}
});
}
Would anyone know a solution to this problem?
Thank you very much,
Daniel
In Android Studio, you have to add your jar into the lib folder, add the dependency into the build.gradle file and call gradlew clean from console. The gradlew is in your project directory.
Check this thread for more details: Android Studio: Add jar as library?

Categories

Resources