关于android的两个活动:错误强制关闭

时间:2011-05-20 22:53:12

标签: android

我想在android中创建两个intent Activity,第一个是

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

和第二个

next.setOnClickListener(new OnClickListener() {

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

打开两项活动是否正确?

所以当我运行它时出现错误第一个意图打开时我点击下一个打开第二个意图它强行关闭并在cat日志上

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.Method.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)

清单

<?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

2 个答案:

答案 0 :(得分:0)

该异常告诉您它无法找到类yaraby.y.HelloItemizedOverlay。 它存在吗? 这是正确的包裹吗? 你有进口吗? 它是否可见且易于访问? 您是否从其他包中导入了具有相同名称的类?

答案 1 :(得分:0)

第一;验证您的课程导入, 第二:如果你的活动在不同的套餐中,你应该在你的minfest上定义它们:

<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>

第三:  尝试将其添加到元素 application 中的清单:

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

点击此链接,它会帮助您:)===&gt; your happyness