首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java.lang.IllegalStateException:在Android中执行Retrofit方法时无法执行该活动的方法

java.lang.IllegalStateException:在Android中执行Retrofit方法时无法执行该活动的方法
EN

Stack Overflow用户
提问于 2014-09-09 08:46:33
回答 1查看 1K关注 0票数 1

我是安卓应用程序开发的新手,.I研究了一些在线教程和wiki,并开始开发将调用API托管在Apache服务器(PHP+SLIM+MySQL)..I上的应用程序,已经创建了一些API,并在RESTClient for Chrome上成功地测试了它们。

对于安卓系统,经过一些研究后,我决定使用Square的改进库,它看起来非常高效(比在android上实现的Apache.http协议快5-6倍,比Volley和Robospice快2-3倍)和非常轻的内存占用。

我创建了一个示例Android项目(使用AndroidStudio0.8beta),并通过遵循他们的文档实现了Rertofit。但是,当我编译了我的项目并将我的apk烧到我的phone...it时,java.lang.IllegalStateException无法执行,.following是我实现的细节。

我不知道如何纠正这个错误,...am,我在声明文件中遗漏了什么,或者没有实现我应该实现的任何方法。

库(包括所有gradle依赖项)--我正在包括

  • Gson 2.3
  • 1.6.1改装
  • okhttp 2.0
  • okhttp-urlconnection 2.0
  • okio 1.0.1

结构

代码语言:javascript
复制
public class MyStructures {
                  public static class Contributor {
                    public String login;
                    public int contributions;
                  }
               }

接口

代码语言:javascript
复制
  public interface MyInterface {

            @GET("/repos/{owner}/{repo}/contributors")
            List<Contributor> contributors(
                    @Path("owner") String owner,
                    @Path("repo") String repo
            );
        }

创建适配器,调用REST方法,结果获取

代码语言:javascript
复制
private static final String API_URL = "https://api.github.com";    
RestAdapter restAdapter = new RestAdapter.Builder()
                        .setEndpoint(API_URL)
                        .build();

                // Create an instance of our GitHub API interface.
                MyInterface myInterface = restAdapter.create(MyInterface.class);


                // Fetch and print a list of the contributors to this library.
                List<Contributor> contributors = myInterface.contributors("square", "retrofit");
                for (Contributor contributor : contributors) {
                  System.out.println(contributor.login + " (" + contributor.contributions + ")");

               }

报表文件:

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication" >
    <!-- added this two permission by looking in to some answer on stackoverflow 
    which i geuss not required for newer android version since googles has given n/w permission by default-->
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MyActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
EN

回答 1

Stack Overflow用户

发布于 2015-01-05 07:29:33

我第一次遇到这个问题是通过在清单中添加以下权限来解决的

代码语言:javascript
复制
<uses-permission android:name="android.permission.INTERNET" /> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25740236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档