【问题标题】:Error : This class should provide a default constructor (.....) [Instantiatable]错误:此类应提供默认构造函数(.....)[可实例化]
【发布时间】:2015-08-13 22:17:46
【问题描述】:

我收到以下错误:

错误:此类应提供默认构造函数(没有参数的公共构造函数)(com.mrad4tech.development.sportss.TwitterAPI)

[Instantiatable]

package com.mrad4tech.development.sportss;

public class TwitterAPI {

    private String twitterApiKey;
    private String twitterAPISecret;
    final static String TWITTER_TOKEN_URL = "https://api.twitter.com/oauth2/token";
    final static String TWITTER_STREAM_URL = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=";

    public TwitterAPI(String twitterAPIKey, String twitterApiSecret){
        this.twitterApiKey = twitterAPIKey;
        this.twitterAPISecret = twitterApiSecret;
    }

    ...
}        

请帮帮我

【问题讨论】:

  • 请发布整个堆栈跟踪。
  • a public constructor with no arguments 的哪一部分不清楚 :)

标签: java android json string


【解决方案1】:

为你的类添加一个默认构造函数TwitterAPI

//Default constructor takes no arguments
public TwitterAPI() { 
}

【讨论】:

    【解决方案2】:

    你需要一个无参数构造函数:

    public TwitterAPI(){
    }
    

    【讨论】:

      【解决方案3】:

      错误说明了一切,您应该提供一个默认构造函数。
      将此添加到您的课程中:

      public TwitterAPI() {
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多