2011-02-18 115 views
2

我的第二個活動沒有開始。 下面是代碼: -Android: - 第二項活動沒有開始?

第一項活動: -

package infy.route; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.Toast; 

public class main extends Activity { 
    /** Called when the activity is first created. */ 

    Context mCtx; 
    final static int START =0; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.welcomescreen); 

     mCtx = this; 
     Thread splashThread = new Thread() { 
     @Override 
     public void run() { 
      try { 
       int waited = 0; 
       while (waited < 2500) { 
        sleep(100); 
        waited += 100; 
       } 
      } catch (InterruptedException e) { 
       // do nothing 
      } finally { 
       finish(); 
       Intent i = new Intent(mCtx,InfyRoutePlanner.class); 
       mCtx.startActivity(i); 
       ((Activity)mCtx).startActivityForResult(i, 2); 
      } 
     } 
     }; 
     splashThread.start(); 
    } 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     // TODO Auto-generated method stub 
     super.onActivityResult(requestCode, resultCode, data); 

     if(requestCode == START) 
     { 

      Toast.makeText(mCtx, Integer.toString(resultCode), Toast.LENGTH_SHORT).show(); 
     } 
    } 


    @Override 
    public void onDestroy(){ 
     super.onDestroy(); 
     finish(); 
    } 

} 

次活動: -

package infy.route; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class InfyRoutePlanner extends Activity { 
    /** Called when the activity is first created. */ 

    Context mCtx; 


public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     setContentView(R.layout.main); 

     mCtx = this; 

     // Setting the buttons with their xml 
     Button btn1 = (Button)findViewById(R.id.btn1); 
     Button btn2 = (Button)findViewById(R.id.btn2); 

     // Button for Prepare Route By Address (Line 30 is this one) 
     btn1.setOnClickListener(new OnClickListener(){ 

//   @Override 
     public void onClick(View v) 
     { 
      // This will start the From Address Activity 
      Intent intent = new Intent(mCtx, FromAddress.class); 

      /*Start Activity*/ 
      mCtx.startActivity(intent); 

      /*Start ActivityForResult*/ 
      ((Activity)mCtx).startActivityForResult(intent, 3); 
     } 
     }); 


     // Action On Clicking Button 2 
     btn2.setOnClickListener(new OnClickListener(){ 

     // @Override 
     public void onClick(View v) 
     { 
      // This will start the activity RoutePlanning using Lat and Long Values 
      Intent intent = new Intent(mCtx, RoutePlanning.class); 

      /*Start Activity*/ 
      mCtx.startActivity(intent); 

      /*Start ActivityForResult*/ 
      ((Activity)mCtx).startActivityForResult(intent, 3); 
     } 
    }); 
} 


} 

這裏是堆棧跟蹤器: -

02-18 20:10:02.253: DEBUG/AndroidRuntime(299): Shutting down VM 
02-18 20:10:02.263: WARN/dalvikvm(299): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 
02-18 20:10:02.263: ERROR/AndroidRuntime(299): Uncaught handler: thread main exiting due to uncaught exception 
02-18 20:10:02.283: ERROR/AndroidRuntime(299): java.lang.VerifyError: infy.route.InfyRoutePlanner$1 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at infy.route.InfyRoutePlanner.onCreate(InfyRoutePlanner.java:30) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.app.ActivityThread.access$2100(ActivityThread.java:116) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.os.Looper.loop(Looper.java:123) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at android.app.ActivityThread.main(ActivityThread.java:4203) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at java.lang.reflect.Method.invoke(Method.java:521) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 
02-18 20:10:02.283: ERROR/AndroidRuntime(299):  at dalvik.system.NativeStart.main(Native Method) 

回答

0

我不認爲這是關係到你的問題,但你兩次啓動活動在activity main

mCtx.startActivity(i); 
((Activity)mCtx).startActivityForResult(i, 2); 

第一次不期待的結果,第二個期待它。通常情況下,你只會開始一次活動。而同樣的「問題」你在activity InfyRoutePlanner 有兩次現在,你的問題,你檢查this thread? 我希望幫助

2

你,包括任何第三方罐子?如果虛擬機發現嘗試加載未通過類驗證階段的類,則會引發VeryifyError。

而且你必須在每個OnClickListener 2個調用給startActivity。

+0

我不包括任何其他jar,代碼工作正常,如果我做的第二項活動的主要活動。我想添加一個啓動畫面到我的項目這就是爲什麼添加啓動畫面。請幫忙。 – Prachur 2011-02-18 14:57:01

+0

@詹姆斯 - 你是否已將第二個活動添加到清單中? – Blundell 2011-02-18 15:00:48

相關問題