2

My second activity is not starting. Below is the code :-

First Activity :-

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();
    }

}

Second Activity :-

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);
        }
    });
}


}

Here is the stack tracer :-

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)
Robby Pond
  • 73,164
  • 16
  • 126
  • 119
Prachur
  • 1,100
  • 7
  • 24
  • 42

2 Answers2

2

Are you including any 3rd party jars? A VeryifyError is thrown when the virtual machine notices that an attempt is made to load a class which does not pass the class verification phase.

Also you have 2 calls to startActivity in each OnClickListener.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • I am not including any other jar, the code is working fine if i an making the second activity the main activity. I want to add a splash screen to my project thats why added the splash screen. please help. – Prachur Feb 18 '11 at 14:57
  • @James - Have you added the second activity to your manifest? – Blundell Feb 18 '11 at 15:00
  • @Blundell second activity is present in manifest. but still not working – Prachur Feb 18 '11 at 15:03
  • what to do if i want a splash screen which starts second page and in second page i am having two buttons which start different activities – Prachur Feb 18 '11 at 15:17
  • i have made the splash screen my main activity , is it ok – Prachur Feb 18 '11 at 15:28
0

I don't think this is related to your problem, but you are starting the activity twice in your activity main

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

The first time without expecting a result, the second one expecting it. Normally, you would start an activity only once. And the same 'issue' you have it twice in your activity InfyRoutePlanner Now, for your problem, have you checked this thread? I hope that helps

Community
  • 1
  • 1
raukodraug
  • 11,519
  • 4
  • 35
  • 37
  • what to do if i want a splash screen which starts second page and in second page i am having two buttons which start different activities – Prachur Feb 18 '11 at 15:16
  • you should only need to start it without expecting a result, unless you need the second activity to let know the first activity about specific scenarios. For a better explanation, see the StartingActivities and Getting Results section in http://developer.android.com/reference/android/app/Activity.html – raukodraug Feb 18 '11 at 15:35