Android 找不到符号类WatchActivity

Android 找不到符号类WatchActivity,android,android-studio,wear-os,Android,Android Studio,Wear Os,我正在使用Android Studio构建一个示例Android Wear应用程序,因此我开始使用API20:Android 4.4(KitKat Wear)创建新的Wear项目。当我构建项目时,它会给我以下错误 Error:(8, 34) error: cannot find symbol class WatchActivity Error:(12, 5) error: method does not override or implement a method from a supertyp

我正在使用Android Studio构建一个示例Android Wear应用程序,因此我开始使用
API20:Android 4.4(KitKat Wear)
创建新的
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>

您的应用程序模块的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'
  }

您是否在清单文件中声明了WatchActivity?您是否针对sdk>=20进行了定向和编译?我已在问题中添加了清单文件内容。请看一看。我需要在文件中外部添加WatchActivity吗?@SAM:请参阅help@EugenPechanec是的,在创建项目时,我选择了最小sdk作为“API20:Android4.4(KitKat Wear)”