N
ningaldi
Neues Mitglied
- 0
Hallo,
ich verzweifel gerade an einer recht dummen aufgabe:
ich möchte eine Checkbox einen Text mittels Code zuweisen. dabei erhalte ich leider immer eine Nullpointerexception in dieser Codezeile.
Entsprechender Code: (Zeile 36 markiert)
Ausschnitt aus dem Manifest:
Ausschnitt aus der XML
Exception:
in anderen teilen der app lässt sich problemlos text von fromularfeldern ändern. weiß vielleicht jemand, wie ich die checkbox gefüllt bekomme?
ich verzweifel gerade an einer recht dummen aufgabe:
ich möchte eine Checkbox einen Text mittels Code zuweisen. dabei erhalte ich leider immer eine Nullpointerexception in dieser Codezeile.
Entsprechender Code: (Zeile 36 markiert)
Code:
public class ToDosActivity extends Activity implements OnClickListener {
public static String TAG = ToDosActivity.class.getSimpleName();
// Layoutelemente
protected TextView headline;
protected Button button_new;
protected CheckBox taskname1;
// Datenbank
private static final String DATABASE_NAME = "todos.db";
private static final String TODOS_TABLE_NAME = "todos";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.todos_start);
showtasks();
headline = (TextView) findViewById(R.id.headline);
button_new = (Button) findViewById(R.id.button_new);
taskname1 = (CheckBox) findViewById(R.id.taskname1);
button_new.setOnClickListener(this);
}
public void showtasks() {
[B] taskname1.setText("test");[/B]
}
}
Code:
<activity android:name="ToDosActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Code:
<CheckBox
android:id="@+id/taskname1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
Code:
01-08 16:44:48.684: ERROR/AndroidRuntime(585): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ningaldi.todos/de.ningaldi.todos.ToDosActivity}: java.lang.NullPointerException
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.os.Looper.loop(Looper.java:123)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at java.lang.reflect.Method.invoke(Method.java:521)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at dalvik.system.NativeStart.main(Native Method)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): Caused by: java.lang.NullPointerException
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at de.ningaldi.todos.ToDosActivity.showtasks(ToDosActivity.java:104)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at de.ningaldi.todos.ToDosActivity.onCreate(ToDosActivity.java:36)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 16:44:48.684: ERROR/AndroidRuntime(585): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
in anderen teilen der app lässt sich problemlos text von fromularfeldern ändern. weiß vielleicht jemand, wie ich die checkbox gefüllt bekomme?