找不到符号类WatchActivity

时间:2015-01-14 17:07:02

标签: android android-studio wear-os

我正在使用Android Studio构建Android Wear应用示例,因此我开始使用Wear创建新的API 20: Android 4.4 (KitKat Wear)项目。当我构建项目时,它给出了以下错误

Error:(8, 34) error: cannot find symbol class WatchActivity
Error:(12, 5) error: method does not override or implement a method from a supertype
Error:(14, 9) error: cannot find symbol variable super
Error:(15, 9) error: cannot find symbol method setContentView(int)
Error:(16, 52) error: cannot find symbol method findViewById(int)

以下是我的来源

package com.example.rahul.myapplication;   
import android.os.Bundle;
import android.support.wearable.activity.WatchActivity;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.TextView;

public class MyActivity  extends WatchActivity {

    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
            @Override
            public void onLayoutInflated(WatchViewStub stub) {
                mTextView = (TextView) stub.findViewById(R.id.text);
                Log.d(TAG, "TextView: " + mTextView.getText() + " view=" + mTextView);
            }
        });
    }
}

当我将光标放在以下行时,我从Intellisense "unused import statement"收到消息

  import android.support.wearable.activity.WatchActivity;

我还尝试清理项目并再次重建它,但它无法正常工作。提前谢谢。

AndroidManifest.xml的内容

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rahul.myapplication" >

    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >
        <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>

</manifest>

1 个答案:

答案 0 :(得分:0)

您的应用模块的 build.gradle 文件应如下所示:

    apply plugin: 'com.android.application'

    android {
      compileSdkVersion 21
      buildToolsVersion "21.1.2"

      defaultConfig {
          applicationId "com.example.rahul.myapplication"
          minSdkVersion 21
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }

  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.google.android.support:wearable:1.1.0'
      compile 'com.google.android.gms:play-services-wearable:6.5.87'
  }