NoSuchMethodError - 更新Glass GDK之后

时间:2014-05-06 15:32:48

标签: google-glass google-gdk

我将Google Glass GDK从xe12更新为xe16。我的应用程序运行良好,直到更新。现在,当我运行应用程序时,玻璃抛出:

java.lang.NoSuchMethodError: com.google.android.glass.app.Card.setText

我已按照以下讨论中的说明进行操作:

[link 1](NoSuchMethodError for Card.setText() in XE16

[link 2](Google Glass updated to KitKat, but new methods aren't showing up in Eclipse?

但是我仍然无法运行我的代码。

我确保Eclipse中的所有内容都是最新的,我的项目构建目标是Glass Development Kit Preview(KitKat),我已经重新启动了Eclipse。

任何建议?

这是创建卡片的代码:

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

import com.Y2014S.MirrorEdge.common_functions.CardScrollViewManager;
import com.google.android.glass.app.Card;
import com.google.android.glass.widget.CardScrollView;
public class MainActivity extends ActionBarActivity
{
private ArrayList<Card> mCards;
private CardScrollView mCardScrollView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    mCards = new ArrayList<Card>(10);
    mCards = createCard(mCards, this, "hello");
    CardScrollViewManager ScrollManager = new CardScrollViewManager(mCards);
    mCardScrollView = ScrollManager.createCardScrollView(mCardScrollView,
            getApplicationContext());
    setContentView(mCardScrollView);
}

public static ArrayList<Card> createCard(ArrayList<Card> mCards,
        final Context appContext, final String headerText)
{
    final Card newCard = new Card(appContext);
    CharSequence cs = headerText;
    newCard.setText(cs);
    mCards.add(newCard);
    return mCards;
}// end of createCard method

}

注意:我将Card添加到方法本身的ArrayList中,并将ArrayList返回到Main Activity以供以后使用。

谢谢!

1 个答案:

答案 0 :(得分:0)

您现在需要使用card.setText(CharSequence xx)。顺便说一句,String实现CharSequence。 您可能需要查看发行说明here

您可以尝试从Activity继承..以下似乎可以做所有事情(没有错误)..(但来自您的私人来源的CardScrollViewManager内容:

package com.example.stackglasstest;

import java.util.ArrayList;

import com.google.android.glass.app.Card;
import com.google.android.glass.widget.CardScrollView;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;



public class MainActivity extends Activity
{
private ArrayList<Card> mCards;
private CardScrollView mCardScrollView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    Context x = this;
    mCards = new ArrayList<Card>(10);
    mCards = createCard(mCards, this, "hello");
    CardScrollViewManager ScrollManager = new CardScrollViewManager(mCards);
    mCardScrollView = ScrollManager.createCardScrollView(mCardScrollView,
            getApplicationContext());
    setContentView(mCardScrollView);
}

public static ArrayList<Card> createCard(ArrayList<Card> mCards,
        final Context appContext, final String headerText)
{
    final Card newCard = new Card(appContext);
    CharSequence cs = headerText;
    newCard.setText(cs);
    mCards.add(newCard);
    return mCards;
}// end of createCard method

}

这是AndroidManifest ......

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

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.stackglasstest.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>