无法解析方法setText - AndroidStudio(Cannot resolve method setText - AndroidStudio)
提前抱歉,这是我用android完成的第一个项目。
我试图在php文件中显示文本,但是setText说它无法解析方法。 我确信这里有很多我做错的事情,但是setText是目前唯一的错误。
private String itemTitle;
private String itemDate;
private String itemContent;
Response.Listener listener = new Response.Listener() {
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);
}
}
Sorry in advance, this is the first project I've done with android.
I am trying to make text in the php file appear, but setText is saying it can't resolve the method. I'm sure there are many things I've done wrong here, but the setText is the only error at the moment.
private String itemTitle;
private String itemDate;
private String itemContent;
Response.Listener listener = new Response.Listener() {
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);
}
}
原文:https://stackoverflow.com/questions/27538674
更新时间:2019-12-11 06:30
最满意答案
String s没有setText()方法。 您可能正在寻找扩展TextView东西。
Strings do not have a setText() method. You are probably looking for something that extends TextView.
2014-12-18
相关问答
SourceSets: 我可以告诉你,它来自基于你的sourceSets基于Eclipse的项目: sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/
...
String s没有setText()方法。 您可能正在寻找扩展TextView东西。 Strings do not have a setText() method. You are probably looking for something that extends TextView.
我将以下配置添加到我的应用程序级build.gradle,以从androidTestCompile for TestUtils中排除播放服务。 这解决了这个问题: configurations {
androidTestCompile.exclude group: 'com.google.android.gms'
androidTestCompile.exclude module: 'play-services:6.1.71'
}
I added the following co
...
在您的适配器中进行更改并将List作为第三个参数传递或从构造函数中删除它,因为我没有看到您在适配器的任何位置使用它。 可能这也是你的错误,所以如果你想使用你在构造函数中传递的列表,你的Adapter实现应该如下所示: import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import andro
...
这在Kotlin 0.12.356中得到修复。 您可能会在相应的问题中看到讨论: KT-7862 。 This is fixed in Kotlin 0.12.356. You may see the discussion in the corresponding issue: KT-7862.
您是否在渲染方法中创建舞台,外观和批处理的新实例? 将它们从渲染方法中移开;) 渲染看起来应该更像这样: @Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
myGame.batch.s
...
要使用ssh密钥,您应该使用ssh访问协议而不是https协议。 您应该将URL更改为以下格式: git@github.com:[user]/[proyect].git
我希望这会有所帮助:D To use ssh key you should use the ssh access protocol instead of https protocol. You should change the url to the format: git@github.com:[user]/[proyect]
...
这主要是因为我使用多通道gradle脚本生成apk,现在我删除它,它不再显示。 That's mainly because i have use multiple-channel gradle script to generate apk, now i remove it, it not show again.
您的顶级gradle文件需要指向maven库源。 见下文。 // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:g
...
我遇到同样的问题,尝试更改API(在layout中使用API 23),尝试将它放到API 21如果它不起作用),请尝试重新启动Android Studio。 这就是你改变API的方式 欲了解更多信息看这个问题 ,这一个 I had the same problem, try to change the API (you are using API 23 on your layout), try to put it to API 21 if it doesn't work try to restar
...