我的应用程序在启动时崩溃了

时间:2018-06-03 04:12:18

标签: android retrofit2

我是android studio的初学者。尝试使用Retrofit进行基本API调用,用于PHP API调用,用于登录。对不起,如果我问这样的问题可能是错误的,请纠正我。

代码:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        prefConfig = new PrefConfig(this);
        apiInterface = ApiClient.getApiClient().create(ApiInterface.class); //Here


        if (findViewById(R.id.fragment_container) != null) {
            if (savedInstanceState != null) {
                return;
            }

            if (prefConfig.readLoginStatus()) {
                getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new WelcomeFragment()).commit();
            } else {
                getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, new LoginFragment()).commit();
            }
        }
    }

当我评论标记为Here的行时,一切都很顺利。

日志错误:

Process: com.example.surya.emorecomender, PID: 9729
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.surya.emorecomender/com.example.surya.emorecomender.MainActivity}: java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
     Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api
        at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:513)
        at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:456)
        at com.example.surya.emorecomender.ApiClient.getApiClient(ApiClient.java:13)
        at com.example.surya.emorecomender.MainActivity.onCreate(MainActivity.java:17)
        at android.app.Activity.performCreate(Activity.java:6956)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6776) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 

1 个答案:

答案 0 :(得分:1)

这是最重要的部分:

./aws route53domains list-domains  --max-items 123
{
    "Domains": []
}

复制Process: com.example.surya.emorecomender, PID: 9729 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.surya.emorecomender/com.example.surya.emorecomender.MainActivity}: java.lang.IllegalArgumentException: baseUrl must end in /: http://10.0.2.2/database_api 并谷歌。