简体   繁体   English

无法解析方法setText-AndroidStudio

[英]Cannot resolve method setText - AndroidStudio

Sorry in advance, this is the first project I've done with android. 预先抱歉,这是我使用android完成的第一个项目。

I am trying to make text in the php file appear, but setText is saying it can't resolve the method. 我正在尝试使php文件中的文本出现,但是setText表示无法解析该方法。 I'm sure there are many things I've done wrong here, but the setText is the only error at the moment. 我确定这里有很多事情做错了,但setText是目前唯一的错误。

private String itemTitle;
private String itemDate;
private String itemContent;

Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
    public void onResponse(JSONObject response) {

        NewsRecord record = new NewsRecord();
        try {
            record.title = response.getString("title");
            record.shortInfo = response.getString("short_info");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        itemTitle.setText(record.title);
        itemDate.setText(record.date);
        itemContent.setText(record.shortInfo);

    }
    };

        Response.ErrorListener errorListener = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        };


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


        Intent intent = getIntent();
        int recordId = intent.getIntExtra("record_id", 0);

        String url = "http://www.tnt.com/projects/newsfeed/getList.php";

        new JsonObjectRequest(url, null, listener, errorListener);


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

String s do not have a setText() method. String没有setText()方法。 You are probably looking for something that extends TextView . 您可能正在寻找扩展TextView东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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