0

我正在尝试使用 Google Play 服务的 Google Maps 演示,但在两行示例代码中返回错误。返回错误的代码如下:

new DemoDetails(R.string.circle_demo, R.string.circle_description,
                CircleDemoActivity.class),

第一行的错误是“构造函数 MainActivity.DemoDetails(int, int, Class) 未定义。” 第二个错误是“CircleDemoActivity 无法解析为类型”。

这可能是一件微不足道的事情,我是 Android 开发的新手,所以请原谅我缺乏专业知识。

这是 MainActivity.java 中的其余代码:

/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.mapdemo;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.example.mapdemo.view.FeatureView;

/**
 * The main activity of the API library demo gallery.
 * <p>
 * The main layout lists the demonstrated features, with buttons to launch them.
 */
public final class MainActivity extends ListActivity {

/**
 * A simple POJO that holds the details about the demo that are used by the List Adapter.
 */
private static class DemoDetails {
    /**
     * The resource id of the title of the demo.
     */
    private final int titleId;

    /**
     * The resources id of the description of the demo.
     */
    private final int descriptionId;

    /**
     * The demo activity's class.
     */
    private final Class<? extends FragmentActivity> activityClass;

    public DemoDetails(
            int titleId, int descriptionId, Class<? extends FragmentActivity> activityClass) {
        super();
        this.titleId = titleId;
        this.descriptionId = descriptionId;
        this.activityClass = activityClass;
    }
}

/**
 * A custom array adapter that shows a {@link FeatureView} containing details about the demo.
 */
private static class CustomArrayAdapter extends ArrayAdapter<DemoDetails> {

    /**
     * @param demos An array containing the details of the demos to be displayed.
     */
    public CustomArrayAdapter(Context context, DemoDetails[] demos) {
        super(context, R.layout.feature, R.id.title, demos);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FeatureView featureView;
        if (convertView instanceof FeatureView) {
            featureView = (FeatureView) convertView;
        } else {
            featureView = new FeatureView(getContext());
        }

        DemoDetails demo = getItem(position);

        featureView.setTitleId(demo.titleId);
        featureView.setDescriptionId(demo.descriptionId);

        return featureView;
    }
}

private static final DemoDetails[] demos = {new DemoDetails(
        R.string.basic_map, R.string.basic_description, BasicMapActivity.class),
        new DemoDetails(R.string.camera_demo, R.string.camera_description,
                CameraDemoActivity.class),
        new DemoDetails(R.string.events_demo, R.string.events_description,
                EventsDemoActivity.class),
        new DemoDetails(R.string.layers_demo, R.string.layers_description,
                LayersDemoActivity.class),
        new DemoDetails(
                R.string.locationsource_demo, R.string.locationsource_description,
                LocationSourceDemoActivity.class),
        new DemoDetails(R.string.uisettings_demo, R.string.uisettings_description,
                UiSettingsDemoActivity.class),
        new DemoDetails(R.string.groundoverlay_demo, R.string.groundoverlay_description,
                GroundOverlayDemoActivity.class),
        new DemoDetails(R.string.marker_demo, R.string.marker_description,
                MarkerDemoActivity.class),
        new DemoDetails(R.string.polygon_demo, R.string.polygon_description,
                PolygonDemoActivity.class),
        new DemoDetails(R.string.polyline_demo, R.string.polyline_description,
                PolylineDemoActivity.class),
        new DemoDetails(R.string.circle_demo, R.string.circle_description,
                CircleDemoActivity.class),
        new DemoDetails(R.string.tile_overlay_demo, R.string.tile_overlay_description,
                TileOverlayDemoActivity.class),
        new DemoDetails(R.string.options_demo, R.string.options_description,
                OptionsDemoActivity.class),
        new DemoDetails(R.string.multi_map_demo, R.string.multi_map_description,
                MultiMapDemoActivity.class),
        new DemoDetails(R.string.retain_map, R.string.retain_map_description,
                RetainMapActivity.class),
        new DemoDetails(R.string.raw_mapview_demo, R.string.raw_mapview_description,
                RawMapViewDemoActivity.class),
        new DemoDetails(R.string.programmatic_demo, R.string.programmatic_description,
                ProgrammaticDemoActivity.class)};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListAdapter adapter = new CustomArrayAdapter(this, demos);

    setListAdapter(adapter);
}

谢谢。

编辑:应用程序崩溃了,我认为是因为谷歌地图与模拟器不兼容,但这是运行它时的 logcat:

04-10 18:40:31.338: W/dalvikvm(2959): Unable to resolve superclass of Lcom/example/mapdemo/BasicMapActivity; (75) 04-10 18:40:31.396: W/dalvikvm(2959): Link of class 'Lcom/example/mapdemo/BasicMapActivity;' failed 04-10 18:40:31.396: E/dalvikvm(2959): Could not find class 'com.example.mapdemo.BasicMapActivity', referenced from method com.example.mapdemo.MainActivity.<clinit> 04-10 18:40:31.396: W/dalvikvm(2959): VFY: unable to resolve const-class 117 (Lcom/example/mapdemo/BasicMapActivity;) in Lcom/example/mapdemo/MainActivity; 04-10 18:40:31.396: D/dalvikvm(2959): VFY: replacing opcode 0x1c at 0x000d 04-10 18:40:31.447: W/dalvikvm(2959): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/example/mapdemo/MainActivity; 04-10 18:40:31.477: W/dalvikvm(2959): Class init failed in newInstance call (Lcom/example/mapdemo/MainActivity;) 04-10 18:40:31.477: D/AndroidRuntime(2959): Shutting down VM 04-10 18:40:31.477: W/dalvikvm(2959): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 04-10 18:40:31.536: E/AndroidRuntime(2959): FATAL EXCEPTION: main 04-10 18:40:31.536: E/AndroidRuntime(2959): java.lang.ExceptionInInitializerError 04-10 18:40:31.536: E/AndroidRuntime(2959): at java.lang.Class.newInstanceImpl(Native Method) 04-10 18:40:31.536: E/AndroidRuntime(2959): at java.lang.Class.newInstance(Class.java:1319) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.app.Instrumentation.newActivity(Instrumentation.java:1054) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.app.ActivityThread.access$600(ActivityThread.java:141) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.os.Handler.dispatchMessage(Handler.java:99) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.os.Looper.loop(Looper.java:137) 04-10 18:40:31.536: E/AndroidRuntime(2959): at android.app.ActivityThread.main(ActivityThread.java:5041) 04-10 18:40:31.536: E/AndroidRuntime(2959): at java.lang.reflect.Method.invokeNative(Native Method) 04-10 18:40:31.536: E/AndroidRuntime(2959): at java.lang.reflect.Method.invoke(Method.java:511) 04-10 18:40:31.536: E/AndroidRuntime(2959): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 04-10 18:40:31.536: E/AndroidRuntime(2959): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-10 18:40:31.536: E/AndroidRuntime(2959): at dalvik.system.NativeStart.main(Native Method) 04-10 18:40:31.536: E/AndroidRuntime(2959): Caused by: java.lang.NoClassDefFoundError: com.example.mapdemo.BasicMapActivity 04-10 18:40:31.536: E/AndroidRuntime(2959): at com.example.mapdemo.MainActivity.<clinit>(MainActivity.java:98) 04-10 18:40:31.536: E/AndroidRuntime(2959): ... 15 more

4

1 回答 1

0

缺少 CircleDemoActivity。添加它,这应该可以解决您的问题。

或者从您的文件中删除对它的所有引用...

于 2013-04-15T21:10:05.207 回答