开发者

Two activities on android: error force close

I want to make two intent Activitys in android, the first one being

    txt=(EditText)findViewById(R.id.txt);
    next = (Button) findViewById(R.id.Button01);   

    next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(yaraby.this, HelloItemizedOverlay.class);
            yaraby.this.startActivity(i);
        }
    }

and the second one

next.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent i = new Intent(Mapy.this, yaraby.class);
        Mapy.this.startActivity(i);
    }
}

Is this right to open two activities?

So the error when I run it the first intent open when I click next to open second intent it force close and on the cat log

05-21 01:00:23.913: VERBOSE/AudioFlinger(95): MixerThread 0xbb50 TID 152 waking up
05-21 01:00:23.933: ERROR/AndroidRuntime(9212): FATAL EXCEPTION: main
05-21 01:00:23.933: ERROR/AndroidRuntime(9212): java.lang.NoClassDefFoundError: yaraby.y.HelloItemizedOverlay
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at yaraby.y.yaraby$1.onClick(yaraby.java:48)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at  android.view.View.performClick(View.java:2408)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at android.view.View$PerformClick.run(View.java:8816)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at android.os.Handler.handleCallback(Handler.java:587)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at android.os.Looper.loop(Looper.java:123)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at android.app.ActivityThread.main(ActivityThread.java:4633)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at java.lang.reflect.Method.invokeNative(Native Method)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at java.lang.reflect.Metho开发者_如何学Cd.invoke(Method.java:521)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-21 01:00:23.933: ERROR/AndroidRuntime(9212):     at dalvik.system.NativeStart.main(Native Method)

the manifest

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

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />    

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".yaraby"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity android:name=".Mapy"
              android:label="@string/app_name">
        <intent-filter>
              <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

<activity android:name=".HelloItemizedOverlay"
              android:label="@string/app_name">
        <intent-filter>
           <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

   package yaraby.y;

                import java.io.BufferedReader;
     import java.io.DataOutputStream;
    import java.io.InputStreamReader;
     import java.net.Socket;

                 import android.app.Activity;
                    import android.content.Intent;
                                  import android.os.Bundle;
                                  import android.view.Vieimport                                                           android.view.View.OnClickListener;
          import android.widget.Button;
                                               import android.widget.EditText;
                                           import android.widget.TextView;
                                                                                                  v          import android.widget.Toast;

mapy import

package yaraby.y;

 import java.io.BufferedReader;
  import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
   import java.net.InetSocketAddress;
 import java.net.Socket;
    import java.net.SocketException;
      import java.util.List;
                                            ///and other 




           public class Mapy extends MapActivity

                        {


 05-21 03:40:37.703: ERROR/AndroidRuntime(12691): FATAL EXCEPTION: main
  05-21 03:40:37.703: ERROR/AndroidRuntime(12691): java.lang.NoClassDefFoundError: yaraby.y.Mapy


The exception tells you that it cannot find the class yaraby.y.HelloItemizedOverlay. Does it exist? Is it the right package? Have you imported it? Is it visible and accessible? Have you imported a class with the same name from a different package?


First ; verify your import of your classes, Second : if you have your activities in different packages , you should define them on your minfest like this :

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".yaraby"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name="mapyPackageName.Mapy"
          android:label="@string/app_name">
    <intent-filter>
          <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity android:name="HelloItemPackageName.HelloItemizedOverlay"
          android:label="@string/app_name">
    <intent-filter>
       <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Third : try to add this to your manifest in the element application :

<uses-library android:name="com.google.android.maps" />

follow this link , it will help you :)===> your happyness

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜