简体   繁体   中英

Base URL connecting to database in Android studio

I am having a problem with android application connecting to my database. Is the code I wrote correct? or do I need to setup a web hosting instead or running localhost server?

public static String BASE_URL = "http://localhost/jobportal/api";

Code:

public interface Consts {
public static String JOB_PORTAL = "JobPortal";

public static String BASE_URL = "http://localhost:8080/jobportal/api";
public static String IS_REGISTER_SEEKER = "is_register_seeker";
public static String IS_REGISTER_RECRUITER = "is_register_recruiter";

/*API DETAILS*/
public static String POST_METHOD = "POST";
public static String SIGNUP_API_SEEKER = "register-new-seeker";
public static String SIGNUP_API_RECRUITER = "register-new-recruiter";
public static String LOGIN_API_SEEKER = "login-seeker";
public static String LOGIN_API_RECRUITER = "recruiter-login";
public static String ACTIVE_JOBS_API = "search-job";
public static String APPLY_JOB_API = "apply-on-job";
public static String POST_JOB_API = "post-job";
public static String GENERAL = "general ";
public static String FILL_SEEKER_PROFILE = "fill-seeker-profile";
public static String FILL_RECRUITER_PROFILE = "fill-recruiter-profile";
public static String SEEKER_CHANGE_PASSWORD = "seeker-change-password ";
public static String RECRUITER_CHANGE_PASSWORD = "recruiter-change-password ";
public static String FORGOT_PASSWORD = "forgot-password ";
public static String GET_RECRUITER_JOBS = "get-recruiter-jobs";
public static String JOB_APPLICATION = "job-application";
public static String DELETE_JOB = "delete-job";
public static String SEEKER_PROFILE_DETAIL_ON_JOB = "seeker-profile-detail-on-job";
public static String GET_RECRUITER_JOB_DETAIL = "get-recruiter-job-detail";

Screenshot taken from IDE

here is my database 在此处输入图片说明

Looks like your URL is missing port# of database . Check the URL with Port# and try connecting using it

First of all, you shouldn't put variable inside interface class. Instead, you can just create a simple class like

public class Consts {
   public static final String JOB_PORTAL = "JobPortal";
   ....
   //etc
}

Second, i suggest you to use Retrofit to connect your mobile phone to database. Read the documentation here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM