0

Good morning - I hope everyone has had an enjoyable weekend.

I am having some issues following the tutorial at https://developer.chrome.com/multidevice/webview/gettingstarted

Everything is going well until I reach the step regarding an edit of the MainActivity class. This is Step 3 in the section Add the WebView: https://developer.chrome.com/multidevice/webview/gettingstarted#add_the_webview

Here is the content of my AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.nathan.myapplication" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MyActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

And here is my MyActivity.java:

package com.example.nathan.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

public class MyActivity extends Activity {
private WebView mWebView; // Added by ND Guthrie 8.15.2014:2229

@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    mWebView = (WebView)findViewById(R.id.activity_my_webview);  // Added by ND Guthrie 8.15.2014:2231
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.my, 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);
}
}

I have tried suggestions based on these links here on stackoverflow:

Error with R class import in android

Android Studio don't generate R.java for my import project

R.id cannot be resolved

For the error with R class import, I have attempted adding the line

import com.TestApp.HelloWebView.R;

But with no success, as TestApp is not recognized. This stands to reason, since I have not named anything 'TestApp' in my app here, but I do not understand how to fix it.

I also tried deleting the generated folder and cleaning and rebuilding the project. However, I obtain the same results.

I know this is probably a silly little thing, but I have been searching google and stackoverflow for days now, and it seems like there is just something I am not seeing.

Any ideas? Please advise.

Thank you very much for your time!

Best, Nathan

Community
  • 1
  • 1
  • `import com.TestApp.HelloWebView.R;` should be import `com.example.nathan.myapplication.R"`. Any way that is no needed if you have the activity in the package `com.example.nathan.myapplication`. But there could be errors in any of your resource files in which case R.java will not be generated. – Raghunandan Aug 18 '14 at 17:07
  • also post `activity_my.xml` to check if the webview with the id `activity_my_webview` exists – Raghunandan Aug 18 '14 at 17:09
  • check if you have a red cross inside your resources, probably you have to fix this to make your project work. – Jorgesys Aug 18 '14 at 17:29

1 Answers1

0

The way it works is that your XML files get compiled into resources in the background by Eclipse, and an R.java gets generated that allows your project to refer to these resources. If you put "R.id.blah" or "R.layout.blah" or whatever into Eclipse and it isn't recognised, it means one of the following:

  1. Your XML files don't have corresponding elements. R.java is being created, but doesn't contain "R.id.blah" or whatever you're using, because your XML files don't contain elements that would compile with those IDs.
  2. R.java couldn't be compiled at all. That'll be the case if there are errors in your project. You're best off making sure that there are no errors (no red crosses anywhere), and then seeing whether R.java appears. Once you've done that, you'll be able to find out what IDs are being generated, and that should point you in the direction of what's missing or inconsistent in your XML files.
chiastic-security
  • 20,430
  • 4
  • 39
  • 67
  • Hi guys, Thanks very much for your quick replies! These responses are indeed closing in on the solution. I have attempted the import com.example.nathan.myapplication.R; and while it seems to help, it is greyed out and as I understand it, unused. I do have the red bar error saying 'cannot resolve symbol activity_my_webview', so I imagine it is a referencing problem. I DO have a generated R.java file. It is in the /source folder. I can post the contents if that is helpful. The activity_my.xml does NOT contain a reference to activity_my_webview. Thanks again. – ND Guthrie Aug 18 '14 at 18:33