gpt4 book ai didi

java - 开始一个新的 Activity (安卓)

转载 作者:行者123 更新时间:2023-11-29 09:46:12 26 4
gpt4 key购买 nike

我正尝试从主要 Activity 开始一个新 Activity ,但在启动应用程序时出现错误应用程序...已意外停止。请再试一次(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>

日志:

 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

最佳答案

list 有两处错误:

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

应该在其他 activity 之外并在 application 中。

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

关于java - 开始一个新的 Activity (安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4511426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com