2010-11-08 440 views
1

我有兩個類作爲trial.java和ImageWoLab0.java(圖片無標籤0)。當我運行我的應用程序時出現錯誤:應用程序意外停止 !!應用程序意外停止!

public void onClick(View v) 
{ 
    switch (v.getId()) 
    { 
    case R.id.btnSequence: 
     Intent intent1 = new Intent(); 
     intent1.setClass(this,ImageWoLab0.class);  /*To open new Screen/Activity */ 
     //intent1.putExtra("String_key", "value"); /*Passing a key/value(Condition) to Activity2.class*/ 
     startActivity(intent1);      /*open the new screen/Activity*/ 
     break; 

    case R.id.btnVideo: 
     Intent intent2 = new Intent(); 
     intent2.setClass(this,Activity2.class); 
     intent2.putExtra("String_key", "value1"); 
     startActivity(intent2); 
     break; 

    case R.id.btnInfo: 
     Intent intent3 = new Intent(); 
     intent3.setClass(this,Activity2.class); 

     intent3.putExtra("String_key", "value2"); 
     startActivity(intent3); 
     break; 
    } 

othar類如:

public class ImageWoLab0 extends Activity implements OnClickListener 

{ 私有靜態字符串TAG = 「標籤」;

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    Log.i(TAG, "abc"); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.image0); 
    ImageButton o1 = (ImageButton) findViewById(R.id.next); 
    o1.setOnClickListener(this); 

} 

@Override 
public void onClick(View v) 
{ 
    switch (v.getId()) 
    { 
    case R.id.next: 
     Intent intent1 = new Intent(); 
     intent1.setClass(this,ImageWoLab1.class); 
     startActivity(intent1); 
     break; 


    } 

} 

}

我一次又一次乾淨甚至再次重建仍顯示相同messageis。我得到的日誌爲:對不起,如果我沒有在正確的格式(我第一次使用的logcat)發送日誌:

11-08 12:48:55.084: INFO/tag(334): abc 
11-08 12:48:55.154: WARN/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334): FATAL EXCEPTION: main 
11-08 12:48:55.204: ERROR/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.Trial/com.example.Trial.ImageWoLab0}: java.lang.ClassCastException: android.widget.ImageView 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.os.Handler.dispatchMessage(Handler.java:99) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.os.Looper.loop(Looper.java:123) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at java.lang.reflect.Method.invoke(Method.java:521) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at dalvik.system.NativeStart.main(Native Method) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334): Caused by: java.lang.ClassCastException: android.widget.ImageView 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at com.example.Trial.ImageWoLab0.onCreate(ImageWoLab0.java:21) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
11-08 12:48:55.204: ERROR/AndroidRuntime(334):  ... 11 more 
11-08 12:48:55.264: WARN/ActivityManager(61): Force finishing activity com.example.Trial/.ImageWoLab0 
11-08 12:48:55.274: WARN/ActivityManager(61): Force finishing activity com.example.Trial/.Trial 

回答

0

感謝Yuliy !!我已經解決了這個問題,其實在XML我正在imageview的上java文件我是在製造的對象

<?xml version="1.0" encoding="utf-8"?> 

而imagebutton as:

ImageButton o1 = (ImageButton) findViewById(R.id.next);
o1.setOnClickListener(this);
現在問題解決了!

0

基礎上的日誌,你要在的onCreate一個ClassCastException。只有一行你在做任何投射。你確定ID name的東西實際上是一個ImageButton而不是別的嗎?

+0

我重新檢查我的圖像,類,清單等一切都很好!!請幫助我,如果你想我也可以發送一些代碼。我想告訴一件事,最近我刪除了一個類文件和所有參考該類也例如在清單,.xml等活動條目我不認爲這個刪除是造成問題! – Alok 2010-11-08 07:50:36