2012-04-14 21 views
2

私はアンドロイド・プログラミングの新機能ですので、ご容赦ください。アンドロイド・ウィジェットの初期化エラー

私は、現在のコードベースのXMLにテキストボックスを追加し、ユーザーがテキストボックスを編集するときに、コード内の変数を変更する必要のある割り当てを持っています。

は、だから私は、テキストボックスを追加し、それが正常に現れていますが、私はそれを初期化しようとすると、アプリが予期せず停止したことをエラーとLogCatでの原料の束を取得します。

CLARIFICATION:最後のテキストボックス(intersymboltime)のみがエラーを引き起こします。私が初期化をコメントアウトすると、すべて正常に動作します。

私のXMLのサンプル(最初の二つは、比較のために、既存のコードからのものである):私のonCreateで

<TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/hostText" 
     android:layout_marginTop="5dp" 
     android:text="@string/portlabel" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:id="@+id/portText" 
     android:layout_width="110dp" 
     android:layout_height="35dp" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/textView3" 
     android:hint="@string/portHint" 
     android:inputType="number|textNoSuggestions" /> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/portText" 
     android:layout_marginTop="14dp" 
     android:text="@string/symboltime" /> 

    <EditText 
     android:id="@+id/intersymboltime" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/textView4" 
     android:ems="10" 
     android:hint="@string/symboltimehint" 
     android:inputType="number" /> 

(最初の2つのコールが比較のために、既存のコードである):

((TextView)findViewById(R.id.hostText)).setText(mServerHost); 
    ((TextView)findViewById(R.id.portText)).setText(new Integer(mServerPort).toString()); 
    ((TextView)findViewById(R.id.intersymboltime)).setText(mClient.portToIntersymbolTime(mServerPort, 1)); 

portToIntersymbolTimeは期待どおりに戻ります。

何が足りないのですか?

EDIT:私のlogcatのログ:

4月13日18:10:17.556:/ ResourceTypeが(716)W:10:17.566ませんパッケージ識別子リソース番号0x00000100 4月13日18の値を取得します: D/AndroidRuntime(716):10:17.566:VM 04から13 18のシャットダウンW/dalvikvm(716):スレッドID = 1:スレッドが捕捉されない例外(グループ= 0x40015560)で終了 4月13日18:10:17.576 :E/AndroidRuntime(716):致命的な例外:メイン 04-13 18:10:17.576:E/AndroidRuntime(716):java.lang.RuntimeException:アクティビティを開始できませんComponentInfo {edu.uw.cs.cse461.sp12 .timingframing/edu.uw.cs.cse461.sp12.timingframing.TimingFramingAndroidActivity}:android.content.res.Resources $ NotFoundException:文字列リソースID#0x100 04-13 18:10:17.576:E/AndroidRuntime(716):android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 04-13 18:10:17.576:E/AndroidRuntime (716):android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 04-13 18:10:17.576:E/AndroidRuntime(716):android.app.ActivityThread.access $ 1500(ActivityThread.java: 117) 4月13日18:10:17.576:E/AndroidRuntime(716):10:17.576:E/AndroidRuntime(android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931) 4月13日18時716):android.os.Handler.dispatchMessage(Handler.java:99) 04-13 18:10:17.576:E/AndroidRuntime(716):android.os.Looper.loop(Looper.java:123) 04-13 18:10:17.576:E/AndroidRuntime(716):android.app.ActivityThread.main(ActivityThread.java:36) 83) 04-13 18:10:17.576:E/AndroidRuntime(716):java.lang.reflect.Method.invokeNative(ネイティブメソッド) 04-13 18:10:17.576:E/AndroidRuntime(716): (Method.java:507) 04-13 18:10:17.576:E/AndroidRuntime(716):com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit .java:839) 4月13日18:10:17.576:E/AndroidRuntime(716):com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)で 4月13日18:10:17.576 :E/AndroidRuntime(716):at dalvik.system.NativeStart.main(ネイティブメソッド) 04-13 18:10:17.576:E/AndroidRuntime(716):原因:android.content.res.Resources $ NotFoundException:文字列リソースID#0x100 04-13 18:10:17.576:E/AndroidRuntime(716):android.content.res.Resources.getText(Resources.java:201) 04-13 18:10:17.576:E/AndroidRuntime(716):android.widget.TextView.setText(TextView。java:2857) 04-13 18:10:17.576:E/AndroidRuntime(716):edu.uw.cs.cse461.sp12.timingframing.TimingFramingAndroidActivity.onCreate(TimingFramingAndroidActivity.java:39) 04-13 18: 10:17.576:E/AndroidRuntime(716):android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-13 18:10:17.576:E/AndroidRuntime(716):android.app.ActivityThread。 performLaunchActivity(ActivityThread.java:1611) 04-13 18:10:17.576:E/AndroidRuntime(716):... 11もっと詳しく

答えて

0

あなたのlogcatを投稿することで、確実に絞り込むことができます。私が最初に見ているのは、戻り値の型がmClient.portToIntersymbolTime(mServerPort, 1)です。 EditTextにはタイプCharSequenceが必要です。 .toStringなどを使用する必要があると確信しています。

+0

戻り値の型はintです。私はprintlnやそれに類するものが必要だと仮定しました。つまりintが大丈夫です。それは誤解ですか? – Colleen

+0

これは誤解であった。 – Colleen

+0

mClientは、あなたが望む文字列を作成してフォーマットするために、toStringメソッドを追加することができる別のクラスの拡張です(既に存在しないと仮定します)。または、それがintであれば、それをintに保存し、toStringを次のように使用します: 'new int symbolTime = mClient.portToIntersymbolTime(mServerPort、1);' then '((TextView)findViewById(R.id.intersymboltime))。setText(symbolTime .toString) ' – cstrutton

0

あなたのコードをデバッグするのは本当に難しいです。 Logcatのエラーログと、portToIntersymbolTimeコードを教えてください。 私が今見ているところによると、あなたのXMLからhostTextが欠落しています。しかし、私は(あなたは((TextView)findViewById(R.id.hostText)).setText(mServerHost);が既存のコードの一部であると言っているので)あなたはxmlのそのセクションを貼り付けていないと推測しています。

+0

申し訳ありませんが、間違っているのは間違いです私はスニペットを提供したので、巨大なコードではありませんでした。エラーログを投稿するのに十分なlogcatを見つけようとします。 – Colleen

+0

eclipseを使用している場合、logcatをドッキング可能なウィンドウとして追加することができます。 「ウィンドウ - >表示 - >その他」に進みます。 Androidを展開してlogcatを選択します。コードを再度実行すると、エラーが赤色で表示されます。 –

関連する問題