开始一项新活动(android)

时间:2010-12-22 16:41:44

标签: java android eclipse android-activity android-emulator

我要从主要活动开始一项新活动,但是当应用程序启动时我收到错误应用程序...意外停止了。请再试一次(在eclipse上没有错误)。这是我的代码:

public class clubber extends Activity {
    protected SearchData sData ;
    protected boolean club;
    protected boolean resto;
    protected boolean bar;
    protected String searchTerms;
    protected String city;
    protected String distance;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       (...)

        //Search button action 
        final Button button = (Button) findViewById(R.id.search);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(clubber.this, "Let's find something !", Toast.LENGTH_SHORT).show();  
                Intent intent = new Intent();
                intent.setClass(clubber.this, Map.class);
                startActivity(intent);
            }
        });
    }
    (...)
}

目标类:

package com.clubber;

import android.os.Bundle;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class Map extends MapActivity {
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
        MapView mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
    }

    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}

的AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.club"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-library android:name="com.google.android.maps" /> 
    <application android:icon="@drawable/icon" android:label="@string/app_name">

    <activity android:name="com.clubber.ClubberActivity" 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=".Map"></activity>

    </application>
    <uses-permission android:name="android.permission.INTERNET" />

</manifest> 

map.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <com.google.android.maps.MapView 
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="*******************************"
        />

    <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        /> 

</RelativeLayout>

logcat:

 D/AndroidRuntime(  512): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime(  512): CheckJNI is ON
D/AndroidRuntime(  512): Calling main entry com.android.commands.am.Am
I/ActivityManager(   60): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.club/com.clubber.ClubberActivity } from pid 512
I/ActivityManager(   60): Start proc com.club for activity com.club/com.clubber.ClubberActivity: pid=520 uid=10036 gids={3003, 1015}
D/AndroidRuntime(  512): Shutting down VM
I/AndroidRuntime(  512): NOTE: attach of thread 'Binder Thread #3' failed
D/dalvikvm(  512): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 1ms+3ms
D/dalvikvm(  512): Debugger has detached; object registry had 1 entries
W/dalvikvm(  520): Unable to resolve superclass of Lcom/clubber/Map; (36)
W/dalvikvm(  520): Link of class 'Lcom/clubber/Map;' failed
E/dalvikvm(  520): Could not find class 'com.clubber.Map', referenced from method com.clubber.ClubberActivity$5.onClick
W/dalvikvm(  520): VFY: unable to resolve const-class 35 (Lcom/clubber/Map;) in Lcom/clubber/ClubberActivity$5;
D/dalvikvm(  520): VFY: replacing opcode 0x1c at 0x0013
D/dalvikvm(  520): VFY: dead code 0x0015-0022 in Lcom/clubber/ClubberActivity$5;.onClick (Landroid/view/View;)V
I/ActivityManager(   60): Displayed com.club/com.clubber.ClubberActivity: +2s131ms
D/dalvikvm(  129): GC_EXPLICIT freed 70K, 50% free 2952K/5831K, external 2638K/3237K, paused 103ms
D/AndroidRuntime(  520): Shutting down VM
W/dalvikvm(  520): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime(  520): FATAL EXCEPTION: main
E/AndroidRuntime(  520): java.lang.NoClassDefFoundError: com.clubber.Map
E/AndroidRuntime(  520):    at com.clubber.ClubberActivity$5.onClick(ClubberActivity.java:121)
E/AndroidRuntime(  520):    at android.view.View.performClick(View.java:2485)
E/AndroidRuntime(  520):    at android.view.View$PerformClick.run(View.java:9080)
E/AndroidRuntime(  520):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(  520):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(  520):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  520):    at android.app.ActivityThread.main(ActivityThread.java:3647)
E/AndroidRuntime(  520):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  520):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  520):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(  520):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(  520):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(   60):   Force finishing activity com.club/com.clubber.ClubberActivity
W/ActivityManager(   60): Activity pause timeout for HistoryRecord{406b0d20 com.club/com.clubber.ClubberActivity}
D/dalvikvm(   60): GC_CONCURRENT freed 1010K, 47% free 4446K/8263K, external 2046K/2554K, paused 11ms+10ms

4 个答案:

答案 0 :(得分:7)

清单有两个问题:

<activity android:name=".Map"></activity> 

应该超出其他活动应用

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

应该在应用程序

使用此xml:

  <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.clubber"
  android:versionCode="1"
  android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

    <uses-library android:name="com.google.android.maps" />     
    <activity android:name=".clubbera" 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=".Map"> </activity>

</application>
<uses-permission android:name="android.permission.INTERNET" />

答案 1 :(得分:2)

您缺少清单中的地图活动。 logcat中的堆栈跟踪可能告诉你这是错误...

答案 2 :(得分:2)

请确保您的Logcat,您有收益,活动未找到例外,这是因为您忘记在Android清单文件中注册您的地图活动

您必须添加活动,如下所示

    <activity android:name=".clubber" 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=".Map"></activity>

</application>

答案 3 :(得分:1)

为了让这个运行,您需要在清单文件中输入以下行:

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

但请注意并在<application>标记内添加如下所示的行:

<application>
    ...
    <uses-library android:name="com.google.android.maps" />
</application>
相关问题