"错误:无法找到符号变量的xml"尝试谷歌分析 [英] "error: cannot find symbol variable xml" while trying google analytics
问题描述
我想实现谷歌分析了我的Android应用之一。我的分析和Android应用开发全新的。我想尝试在谷歌开发者网站给出的例子。当试图编译他们的code,我得到指点分析应用程序的Java文件中的错误, mTracker = analytics.newTracker(R.xml.global_tracker);
行,的.xml突出显示。我在这里公布了整个code。
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.
这是AnalyticsApplication.java
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;
}
}
我Global_tracker.xml文件
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>
我的清单文件
<?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.
感谢。
推荐答案
您需要在您的资源文件夹,名为 XML
以创建一个新的文件夹和文件移动到文件夹。另外,还要确保你,因为你的问题正确地调用布局的名字,你写 Global_tracker.xml
而不是 global_tracker.xml
。这是非常重要的。
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.
希望有所帮助。
这篇关于&QUOT;错误:无法找到符号变量的xml&QUOT;尝试谷歌分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!