Android: - 第二项活动没有开始?

时间:2011-02-18 14:47:22

标签: 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)

2 个答案:

答案 0 :(得分:2)

您是否包括任何第三方罐子?当虚拟机注意到尝试加载未通过类验证阶段的类时,将引发VeryifyError。

此外,您还在每个OnClickListener中调用了两次startActivity。

答案 1 :(得分:0)

我认为这与您的问题无关,但您在activity main

中开始了两次活动
mCtx.startActivity(i);
((Activity)mCtx).startActivityForResult(i, 2);

第一次没有期待结果,第二次期待它。通常,您只会启动一次活动。同样的'问题'你在activity InfyRoutePlanner中有两次 现在,针对您的问题,您检查了this thread吗? 我希望有帮助