Gear Fit SDK IllegalStateException

时间:2015-04-02 08:28:09

标签: android samsung-mobile

我最近从XDA-Developers-forum下载了Gear Fit-SDK并尝试了pdf文件中的示例。

应用程序正在启动,我可以单击ListViewItem以在Gear Fit上启动ExampleDialog。但后来我收到以下错误:

04-01 15:00:52.748  29498-29498/de.chrosey.gearfitone E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.chrosey.gearfitone, PID: 29498
java.lang.IllegalStateException: Scup is not initialized
        at com.samsung.android.sdk.cup.ScupDialog.<init>(Unknown Source)
        at de.chrosey.gearfitone.cup.HelloCupDialog.<init>(HelloCupDialog.java:15)
        at de.chrosey.gearfitone.MainActivity$1.onItemClick(MainActivity.java:39)
        ...

以下是我的文件:

MainActivity.java

public class MainActivity extends ActionBarActivity {

String[] NAMES = {"Hello Cup"};
private HelloCupDialog mHelloCupDialog = null;

private static final int Hello_Cup = 0;
private ListView mListView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, NAMES);
    mListView = (ListView) findViewById(R.id.demo_list);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            if (position == Hello_Cup) {
                if (mHelloCupDialog == null) {
                    mHelloCupDialog = new HelloCupDialog(
                            getApplicationContext());
                } else {
                    mHelloCupDialog.finish();
                    mHelloCupDialog = null;
                }
            }
        }
    });
}[...]}

HelloCupDialog.java

public class HelloCupDialog extends ScupDialog {

public HelloCupDialog(Context context) {
    super(context);                      //<-- this is where the error appears 
}

@Override
protected void onCreate(){
    super.onCreate();
    setBackEnabled(true);
    ScupLabel helloLabel = new ScupLabel(this);
    [...]
    setBackPressedListener(new BackPressedListener() {
        @Override
        public void onBackPressed(ScupDialog scupDialog) {
            finish();
        }
    });
}}

的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.chrosey.gearfitone">

<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="com.samsung.android.sdk.permission.SAMSUNG_CUP_SERVICE"/>

<application
    [...]
    <activity
        [...]
        <intent-filter>
            <action android:name="com.samsung.android.sdk.cup"/>
        </intent-filter>
    </activity>
    <meta-data
        android:name="SAMSUNG_CUP_APP"
        android:value="app_name;ic_launcher;true" />
</application>

我正在测试三星S4,Lollipop StockRom。 IDE是Android Studio 1.1。

有人知道为什么它不能像PlayStore的其他支持杯子的应用那样工作吗?

1 个答案:

答案 0 :(得分:0)

在创建ScupDialog实例之前,您需要在MainActivity中初始化Scup。在setContentView之后添加以下代码。

Scup scup = new Scup();
    try {
        scup.initialize(this);
    }catch (Exception e){}

希望这很清楚!