android - R.string.close ,close 无法解析或不是字段

标签 android mobilefirst-studio

我正在做我的第一个 android 学习教程,但遇到了标题描述的这个错误..这是我试图在 Eclipse 上做的应用程序,java,这是我的代码..(代码是自动生成的由项目)

package com.HelloWorkLight;
import android.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;

import org.apache.cordova.CordovaActivity;``

import com.worklight.androidgap.api.WL;
import com.worklight.androidgap.api.WLInitWebFrameworkResult;
import com.worklight.androidgap.api.WLInitWebFrameworkListener;

public class HelloWorkLight extends CordovaActivity implements      WLInitWebFrameworkListener {

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    WL.createInstance(this);

    WL.getInstance().showSplashScreen(this);

    WL.getInstance().initializeWebFramework(getApplicationContext(), this);

}

/**
 * The IBM MobileFirst Platform calls this method after its initialization is complete and web resources are ready to be used.
 */
public void onInitWebFrameworkComplete(WLInitWebFrameworkResult result){
    if (result.getStatusCode() == WLInitWebFrameworkResult.SUCCESS) {
        super.loadUrl(WL.getInstance().getMainHtmlFilePath());
    } else {
        handleWebFrameworkInitFailure(result);
    }
}

private void handleWebFrameworkInitFailure(WLInitWebFrameworkResult result){
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setNegativeButton(R.string.close, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which){
            finish();
        }
    });

    alertDialogBuilder.setTitle(R.string.error);
    alertDialogBuilder.setMessage(result.getMessage());
    alertDialogBuilder.setCancelable(false).create().show();
}
}

提前谢谢你:)

最佳答案

检查文件values/strings.xml查看是否有该名称的字符串。否则,您可以添加它:

<string name="close">Close</string>

您可能还想尝试 Cancel而不是 Close ,因为这是一般做法。

如果那不是你的问题,通常这些情况下的问题是 import android.R .尝试删除它并重新构建您的项目。

注意:当您使用常用字符串时,请确保使用它们的完全限定名称以避免潜在问题:android.R.string.no ,例如。

如果类文件不在根包中,则导入 R像这样:my.packagename.R

关于android - R.string.close ,close 无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32444385/

相关文章:

java - 尝试启动应用程序时出现 Eclipse "Permission denied"错误

android - 即使应用程序在前台,如何让 FCM 显示通知?

ibm-mobilefirst - IBM MobileFirst 7.0 - 未捕获的 ReferenceErrors : WLJQ is not defined, WL 未定义

iOS 应用程序无法连接到 MobileFirst 服务器

android - IBM Mobilefirst 7.0 - 提供期间的 JSONStore 错误无法定位符号 "CBB_add_u16"

java - Mojo 执行异常 : Maven with Android

android - 应用程序兼容性 21 : name = colorPrimary not working together with name = actionBarStyle

java - 如何让volley onResponse在UnitTest线程中运行

ibm-mobilefirst - 无法将 HelloWorld 应用程序部署到 MobileFirst Development Server