android-wear - Android Wear: 放大 android.support.wearable.view.WatchViewStub 时出错

  显示原文与译文双语对照的内容
0 0

启动可穿戴演示应用程序时,我收到以下错误消息:

inflating android.support.wearable.view.WatchViewStub 时出错"

异常堆栈跟踪:

 FATAL EXCEPTION: main
 Process: com.example.demowearapp, PID: 1503
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demowearapp/com.example.demowearapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.wearable.view.WatchViewStub
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
 at android.app.ActivityThread.access$800(ActivityThread.java:138)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:136)
 at android.app.ActivityThread.main(ActivityThread.java:5026)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:515)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
 at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.wearable.view.WatchViewStub
 at android.view.LayoutInflater.createView(LayoutInflater.java:620)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
 at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
 at android.app.Activity.setContentView(Activity.java:1930)
 at com.example.demowearapp.MainActivity.onCreate(MainActivity.java:15)
 at android.app.Activity.performCreate(Activity.java:5242)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
. . . 11 more
 Caused by: java.lang.reflect.InvocationTargetException
 at java.lang.reflect.Constructor.constructNative(Native Method)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at android.view.LayoutInflater.createView(LayoutInflater.java:594)
. . . 21 more
 Caused by: java.lang.NoClassDefFoundError: android.support.wearable.R$styleable
 at android.support.wearable.view.WatchViewStub.<init>(WatchViewStub.java:52)
 at android.support.wearable.view.WatchViewStub.<init>(WatchViewStub.java:46)
. . . 24 more

我的MainActivity:

public class MainActivity extends Activity {
 private TextView mTextView;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 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);
 }
 });
 }
}

我的activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/watch_view_stub"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 app:rectLayout="@layout/rect"
 app:roundLayout="@layout/round"
 tools:context="com.example.demowearapp.MainActivity"
 tools:deviceIds="wear"> 
</android.support.wearable.view.WatchViewStub>

演示项目来自: Android Wear 模板

我正在使用 Eclipse Luna 。 如果我直接膨胀 R.layout.rect

时间:原作者:1个回答

0 0

似乎你还没有包括支持磨损库项目

Caused by: java.lang.NoClassDefFoundError: android.support.wearable.R$styleable
 at android.support.wearable.view.WatchViewStub.<init>(WatchViewStub.java:52)
 at android.support.wearable.view.WatchViewStub.<init>(WatchViewStub.java:46)
. . . 24 more

( gradle等价编译'com 。google 。android支持:可穿戴:1.1.0')

  1. 从这里下载从下载的库 zip 。
  2. 解压并创建 Eclipse android库项目
  3. 将库项目添加到现有项目

解压缩并重试

原作者:
...