ClassNotFoundException happening only with Android Application

  • Replies:3
Roberto Acevedo
  • Forum posts: 2

Feb 4, 2014, 4:00:47 AM via Website

I'm creating an application that would pull data from a database. The problem is that for some reason it throws a ClassNotFoundException when executing the following line of code

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

I've made this work on a regular Java application. Hence, I already added the jar file as part of the class path. I've done the same things I did for the regular java application, and it breaks only in Android...

Should I be doing something extra for android application?


Thanks.

Reply
Roberto Acevedo
  • Forum posts: 2

Feb 4, 2014, 3:27:13 PM via Website

Also,

Just for kicks, I added the JRE System libraries (jre7) in the Android application, and it still throws the exception.

Reply
KrayZ Logic
  • Forum posts: 17

Feb 13, 2014, 5:08:43 PM via Website

You might need to link the whole library project instead of just adding a jar. In Eclipse, if you import the library project into your workspace, you can right click your android project and go to Properties>Android and link the whole library project. I've had to do that for Google Games and Facebook, otherwise it throws ClassNotFoundExceptions.

Reply
Pascal P.
  • Admin
  • Forum posts: 11,286

Feb 19, 2014, 8:31:06 PM via App

You have to add the lib to android build path which makes sure building the jar into the application

LG Pascal //It's not a bug, it's a feature. :) ;)

Reply