Android Textview : no such element exception



I'm having troubles when retrieving string from my textview. In my XML code :



<TextView
android:id="@+id/trackTitle1"
android:layout_weight="1"
android:background="#a09f9f"
android:gravity="center"
android:padding="8dip"
android:text="test 1"
android:textColor="#000000" />*


In my OnCreate method :



TextView tx = (TextView)findViewById(R.id.trackTitle1);
Log.w("nope", tx.getText().toString());


App is crashing when reaching the



Log.w



With a NosuchElementException Any idea why ? Thanks.


Edit : here's the logcat :



FATAL EXCEPTION: main
Process: com.example.beatptop10, PID: 5352
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.beatptop10/com.example.beatptop10.MainActivity}: java.util.NoSuchElementException
E/AndroidRuntime(5352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
E/AndroidRuntime(5352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
E/AndroidRuntime(5352): at android.app.ActivityThread.access$800(ActivityThread.java:145)
E/AndroidRuntime(5352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
E/AndroidRuntime(5352): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(5352): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(5352): at android.app.ActivityThread.main(ActivityThread.java:5081)
E/AndroidRuntime(5352): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(5352): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(5352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
E/AndroidRuntime(5352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(5352): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(5352): Caused by: java.util.NoSuchElementException
E/AndroidRuntime(5352): at java.util.LinkedList.getFirstImpl(LinkedList.java:538)
E/AndroidRuntime(5352): at java.util.LinkedList.getFirst(LinkedList.java:530)
E/AndroidRuntime(5352): at com.example.beatptop10.MainActivity.onCreate(MainActivity.java:72)
E/AndroidRuntime(5352): at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime(5352): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(5352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
E/AndroidRuntime(5352): ... 11 more

No comments:

Post a Comment