Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

java - "error: cannot find symbol variable xml" while trying google analytics

I am trying to implement google analytics for one of my android apps. I am totally new for analytics and android app development. I thought of trying the examples given in the google developers site. When trying to compile their code, I am getting the error pointing the analytics application java file, mTracker = analytics.newTracker(R.xml.global_tracker); line, .xml is highlighted. I posted the whole code here.

This is AnalyticsApplication.java

package com.google.samples.quickstart.analytics;

import android.app.Application;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;

public class AnalyticsApplication extends Application {
  private Tracker mTracker;

  synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
      GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
      // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
      mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
  }
}

My Global_tracker.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--Replace placeholder ID with your tracking ID-->
    <string name="ga_trackingId">UA-XXXXXXXX-X</string>

    <!--Enable automatic activity tracking-->
    <bool name="ga_autoActivityTracking">true</bool>

    <!--Enable automatic exception tracking-->
    <bool name="ga_reportUncaughtExceptions">true</bool>
</resources>

My manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.samples.quickstart.analytics">

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

    <application
        android:name=".AnalyticsApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            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>
</manifest>

I have already spent two complete days in this issue, and I need your suggestion to go forwards.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to create a new folder in your res folder called xml and move your file to that folder. Also make sure you call the layout name correctly because in your question, you wrote Global_tracker.xml instead of global_tracker.xml. This is so important.

Hope that helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...