android studio cannot resolve method,无法解析方法setText - AndroidStudio(Cannot resolve method setText - A...

2023-05-16

无法解析方法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

...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android studio cannot resolve method,无法解析方法setText - AndroidStudio(Cannot resolve method setText - A... 的相关文章

  • JKS、BKS 和 PKCS12 文件格式

    我正在设置一个无头服务器 该服务器使用用户提供的数据 JS CSS HTML 密钥库 为 Android 构建 Phonegap 混合应用程序 我想进行一些基本的客户端检查 以确保上传的密钥库有效 对于 JKS 文件 我发现可以通过确保提供
  • 如何在发布版本中使用 Zebra EMDK?

    所以我有一台 Zebra MC330M 设备 我之前创建了一个应用程序 我想使用 PDA 内置的条形码扫描仪 如果在调试模式下运行我的应用程序 一切正常 我可以读取条形码 但是如果我创建暂存或释放版本 apk 则条形码读取器不活动 因此如果
  • 使用 ArrayAdapter 的 ListView 中的按钮

    我有一个使用 POJO 类填充的 ArrayAdapter 列表视图由 2 个布局组成 1 代表菜单项 1 代表类别 带分隔符的列表视图很好 后来我尝试在每个菜单项行中添加一个按钮来编辑其中的详细信息 当我尝试获取单击按钮的行的位置时 我遇
  • Android Material主题alpha颜色问题

    我已经创建了一个构建版本为 5 0 的应用程序 我在下面编写了主题
  • Android Activity 和 Service 关系 - 暂停后、停止后

    假设创建了 Activity A 然后 A 启动了一个 Service S 并将其自身绑定到 S S 通知 A 更新 这将导致 A 的状态发生变化 Android 暂停或停止 A 后 A 和 S 会发生什么 例如 暂停 A 是否会自动解除它
  • 在android中以编程方式创建布局 - 问题

    我正在使用以下代码动态创建 FrameLayout mylayout java FrameLayout layout new FrameLayout this FrameLayout LayoutParams layoutparams ne
  • 如何使用RecyclerView.State保存RecyclerView滚动位置?

    我有一个关于 Android 的问题RecyclerView State http developer android com reference android support v7 widget RecyclerView State h
  • Android 可检查子菜单选项

    所以我有一个用于选项菜单项的子菜单 我想要一个可检查条目的列表 用户可以根据需要选择 取消选择多个条目 我无法解决的唯一问题是如何防止单击其中一个复选框时关闭选项菜单 我看到 PerformShortcut 有一个 FLAG PERFORM
  • GSON:自定义对象反序列化

    好吧 我编辑了这个问题 因为它不够清楚 Edit 2 更新了 JSON 文件 我在 Android 应用程序中使用 GSON 我需要解析来自服务器的 JSON 文件 而且有点太复杂了 我不想让我的对象结构太重 所以我想简化内容 所以我的对象
  • 如何设置上拉刷新SwipeRefreshLayout

    我看到很多 ListView 下拉刷新的库 但是当从上到下拉动时它们是工作的 但是从下到上拉动时我如何刷新 我可以用这个做吗滑动刷新布局 http developer android com reference android suppor
  • GCM(Google 云消息传递)是否需要 Google 帐户?

    我需要编写一个简单的应用程序来获取推送通知 我使用 GCM 它使用 Google Play 服务来获取信息 我的问题是 要访问 GCM 是否需要 Google 帐户 我可以使用其他电子邮件帐户来识别设备吗 有没有其他方法可以获取另一个电子邮
  • 为什么设置 MediaRecorder 时显示错误 IllegalStateException?

    我的代码设置 MediaRecorder 它显示行集质量错误 mMediaRecorder new MediaRecorder Step 1 Unlock and set camera to MediaRecorder mCamera st
  • Android Youtube API 可用吗? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 有适用于 Android 的 YouTube API 吗 如果不是 除了通过网络浏览器之外 如何从 Yo
  • Android 如何从我的应用程序使用 SD 卡中的文件路径预览图像

    文件存在于sdcard image jpg我想创建我自己的应用程序 活动 按下按钮时 需要使用内置图像查看器显示存储在 SD 卡中的图像 按图像查看器中的后退按钮后 它应该返回到我正在运行的应用程序 需要一些帮助 您可以为此创建一个具有适当
  • 未调用内容提供商 query() (Android TV)

    据报道 我正在尝试将我的应用程序纳入 Android TV 全局搜索中文档 http developer android com training tv discovery searchable html我必须创建以下内容 内容提供商 可搜
  • 如何将 currentTimeMillis 转换为可读的日期格式? [复制]

    这个问题在这里已经有答案了 我想用currentTimeMillis两次 这样我就可以计算持续时间 但我也想以用户可读的格式显示时间和日期 我遇到了麻烦currentTimeMillis有利于计算 但我看不到内置函数可以转换为合适的时间或时
  • Android 图标与徽标

    The
  • Android 可扩展 GridView 就像 Google 图像一样

    我想创建可扩展的 GridView 其行为类似于 Google 图像页面 我想知道如何实现这样的功能 当我单击其中一张图像时 页面会展开并显示图片的详细信息 Android 中是否可以做类似的事情 Images grid Expanded
  • 动画结束后更改视图位置

    我开发了一个基于ViewGroup我的问题是我需要在动画结束后保存项目的位置 我打了电话setFillAfter true 在我创建的动画对象中AnimationListener并在其中onAnimationEnd方法调用View layo
  • 如何为背景图像添加内边距

    我有一个LinearLayout其中有一个背景图像 一个 9 修补的 png 文件 如何向左和右添加填充 以使背景图像不占据整个宽度 我努力了android paddingLeft and android paddingRight 但这并没

随机推荐