activity aufruf, absturz

  • Antworten:3
imoney91
  • Forum-Beiträge: 34

09.01.2012, 15:05:13 via Website

Hallo Community,

ich hab folgendes Problem. Mit einem ImageButton löse ich in dem Event ein Activity-Aufruf aus, aber aus irgendeinem Grund stürzt es immer ab.

Logcat:
1101-09 14:58:00.463: E/AndroidRuntime(1125): FATAL EXCEPTION: main
2201-09 14:58:00.463: E/AndroidRuntime(1125): java.lang.RuntimeException: Unable to start activity ComponentInfo{project.app/project.app.AuswahlEins}: java.lang.ClassCastException: android.widget.ImageButton
3301-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
4401-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
5501-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
6601-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
7701-09 14:58:00.463: E/AndroidRuntime(1125): at android.os.Handler.dispatchMessage(Handler.java:99)
8801-09 14:58:00.463: E/AndroidRuntime(1125): at android.os.Looper.loop(Looper.java:143)
9901-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.ActivityThread.main(ActivityThread.java:4914)
101001-09 14:58:00.463: E/AndroidRuntime(1125): at java.lang.reflect.Method.invokeNative(Native Method)
111101-09 14:58:00.463: E/AndroidRuntime(1125): at java.lang.reflect.Method.invoke(Method.java:521)
121201-09 14:58:00.463: E/AndroidRuntime(1125): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
131301-09 14:58:00.463: E/AndroidRuntime(1125): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
141401-09 14:58:00.463: E/AndroidRuntime(1125): at dalvik.system.NativeStart.main(Native Method)
151501-09 14:58:00.463: E/AndroidRuntime(1125): Caused by: java.lang.ClassCastException: android.widget.ImageButton
161601-09 14:58:00.463: E/AndroidRuntime(1125): at project.app.AuswahlEins.onCreate(AuswahlEins.java:21)
171701-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
181801-09 14:58:00.463: E/AndroidRuntime(1125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
191901-09 14:58:00.463: E/AndroidRuntime(1125): ... 11 more

und hier der Aufruf
11package project.app;
22
33import android.app.Activity;
44import android.content.Intent;
55import android.os.Bundle;
66import android.view.View;
77import android.widget.Button;
88
99public class AuswahlEins extends Activity {
1010 /** Called when the activity is first created. */
1111 @Override
1212 public void onCreate(Bundle savedInstanceState) {
1313 super.onCreate(savedInstanceState);
1414 setContentView(R.layout.auswahleins);
1515
1616
1717
1818 //Button Event
1919
2020 //auswahleins ok button
2121 Button okButton = (Button)findViewById(R.id.imageButton1);
2222 okButton.setOnClickListener(new View.OnClickListener(){
2323 @Override
2424 public void onClick(View v) {
2525 Intent in1 = new Intent(AuswahlEins.this,AuswahlZwei.class);
2626 startActivity(in1);
2727 }
2828 } );
2929
3030 }
3131}

Bitte um Hilfe

Gruß Nguyen

Antworten
Felix
  • Forum-Beiträge: 259

09.01.2012, 15:29:09 via Website

Tach!


Mit einem ImageButton löse ich in dem Event ein Activity-Aufruf aus, aber aus irgendeinem Grund stürzt es immer ab.

… java.lang.ClassCastException: android.widget.ImageButton …

… Button okButton = (Button)findViewById(R.id.imageButton1); …

Button ist kein Vorfahre von ImageButton, der ImageButton kann also nicht nach Button gecastet werden.

Felix.

P.s. Du hast Code aus dem Forum kopiert, den du zuerst in einem anderen Thread gepostet hattest. Dabei sind jetzt einmal zu viel Zeilennummern entstanden, die man nur aufwendig wieder rausbekommt, wenn man den Code zu Nachvollziehen kopieren möchte. Bitte beim Kopieren von Code aus dem Forum nicht die Anzeige im Forum nehmen, sondern das Original, was man erhält, wenn man „Antworten mit Zitat“ wählt.

Antworten
imoney91
  • Forum-Beiträge: 34

09.01.2012, 15:38:25 via Website

OMG Gott lass Hirn regnen. xD
Die Weihnachtsferien haben mir mein Hirn weggeblasen.

Danke für den Hinweis.

Vielen Dank für die Hilfe hat funktioniert ^^

Antworten