2

i'm doing my first android learning tutorial , but stuck at this error that the title describes ..this is an app i'm trying to do on Eclipse , java , here is my code..(code is auto generated by the project)

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();
}
}

thank you in advance :)

Jaap
  • 81,064
  • 34
  • 182
  • 193
CriminalDuck
  • 195
  • 3
  • 11
  • 1
    I think you imported the wrong `R` class. `import android.R;` – theapache64 Sep 07 '15 at 18:49
  • I have it as R.java >> then R class in there , in the /gen folder – CriminalDuck Sep 07 '15 at 19:00
  • Try replacing `import android.R;` with `import your.application.package.R`. where `your.application.package` is your application package's name. – theapache64 Sep 07 '15 at 19:18
  • Doesn't seem to be the issue , since java is accessing all the R class components and the error message gets hidden once i create a null string called cancel , but is that really the solution? – CriminalDuck Sep 07 '15 at 19:45

1 Answers1

1

Check the file values/strings.xml to see if there is a string by that name. Otherwise, you can add it:

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

You may also want to try Cancel instead of Close, as this is general practice.

If that wasn't your problem, usually the problem in these cases is with import android.R. Try removing it and doing a clean build of your project.

Note: When you're using stock strings, make sure you use their fully-qualified name to avoid potential problems: android.R.string.no, for example.

If the class files aren't in the root package, you import R like this: my.packagename.R

pez
  • 3,859
  • 12
  • 40
  • 72
  • Yes i have strings called close and cancel in {values/strings.xml} – CriminalDuck Sep 07 '15 at 18:57
  • Okay ,question , i have the close / cancel strings in strings.xml but they aren't in the R class , how could i include them proberly to get the error to go away? – CriminalDuck Sep 07 '15 at 19:04
  • @CriminalDuck You really shouldn't be adding anything to `R`. Have you tried removing the import and doing a clean build? Normally that will remove these issues. – pez Sep 07 '15 at 19:25
  • Yup i've tried that and the same error is poping up , Java suggesting me to create cancel or close string in R class to pass that error , but i don't think i should change anything in the R , and according to strings.xml , my values are already there but are unread . – CriminalDuck Sep 07 '15 at 19:31