开发者

Starting a new activity (android)

i'm tring to start a new activity from the main one but i'm getting an error when the application is launched the application ... has stopped unexpectedly. please try again (no error on eclipse ). that's my code:

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

the target class:

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.开发者_如何学JAVAmain(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


There are two things wrong with the manifest:

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

should be outside the other activity and in application.

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

should be inside application

Use this 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" />


You are missing the Map activity in your manifest. The stacktrace in logcat is probably telling you that is the error...


pls ensure your Logcat, that you had yield, Activity Not Found Exception, this is because you had forgot to register your map activity in Android manifest file.

you have to add the Activity as shown below

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


In order to have this running you need to put in the manifest file the following line:

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

but please pay attention and add the line inside the <application> tag like bellow:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜