gpt4 book ai didi

android - 在 setContentView 找不到源 ~ android 编程

转载 作者:太空狗 更新时间:2023-10-29 14:18:41 27 4
gpt4 key购买 nike

我是 android 编程新手。我尝试在 android 设备 (4.1.2) 上显示简单的 Google map 。

我在 ActivityManifest.xml 上添加了所有权限和 google api key

这是 activity_maps.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" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>

</RelativeLayout>

这是 MapsActivity.java

package com.example.androidmapsapp;

import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.MapActivity;

public class MapsActivity extends MapActivity {

GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
try {
// Loading map
initilizeMap();

} catch (Exception e) {
e.printStackTrace();
}

//GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
//googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.maps, menu);
return true;
}

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

private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}

@Override
protected void onResume() {
super.onResume();
initilizeMap();
}

日志猫

09-26 17:09:51.476: E/Trace(26750): error opening trace file: No such file or directory (2)
09-26 17:09:51.501: I/System.out(26750): Sending WAIT chunk
09-26 17:09:51.501: W/ActivityThread(26750): Application com.example.androidmapsapp is waiting for the debugger on port 8100...
09-26 17:09:51.526: I/dalvikvm(26750): Debugger is active
09-26 17:09:51.716: I/System.out(26750): Debugger has connected
09-26 17:09:51.716: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:51.916: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.116: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.316: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.516: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.716: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:52.921: I/System.out(26750): waiting for debugger to settle...
09-26 17:09:53.121: I/System.out(26750): debugger has settled (1377)
09-26 17:09:54.416: D/dalvikvm(26750): threadid=1: still suspended after undo (sc=1 dc=1)
09-26 17:11:15.291: E/Trace(27618): error opening trace file: No such file or directory (2)
09-26 17:11:15.306: I/System.out(27618): Sending WAIT chunk
09-26 17:11:15.306: W/ActivityThread(27618): Application com.example.androidmapsapp is waiting for the debugger on port 8100...
09-26 17:11:15.316: I/dalvikvm(27618): Debugger is active
09-26 17:11:15.506: I/System.out(27618): Debugger has connected
09-26 17:11:15.506: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:15.706: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:15.906: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.106: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.306: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.511: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.711: I/System.out(27618): waiting for debugger to settle...
09-26 17:11:16.911: I/System.out(27618): debugger has settled (1404)
09-26 17:11:18.246: D/dalvikvm(27618): threadid=1: still suspended after undo (sc=1 dc=1)
09-26 17:11:23.271: D/dalvikvm(27618): threadid=1: still suspended after undo (sc=1 dc=1)
09-26 17:11:23.271: D/dalvikvm(27618): GC_CONCURRENT freed 172K, 9% free 9639K/10503K, paused 22ms+4ms, total 56ms
09-26 17:11:23.276: W/CursorWrapperInner(27618): Cursor finalized without prior close()

调试“setContentView(R.layout.activity_maps);”它给出找不到源!

最佳答案

我认为您的问题在于您的 Activity 扩展了 MapActivity,这对于 Google Map API V1 是正确的,但不应该用于 Google Maps API V2。应使用简单的 ActivityFragmentActivity,具体取决于您的目标平台。

在您的情况下,只需尝试更改此行:

public class MapsActivity extends MapActivity {

为此:

public class MapsActivity extends Activity {

如果您仍然遇到问题,可以阅读我写的这篇将 Google Maps API V2 集成到您的应用程序中的博文,看看这是否对您有帮助:

Google Maps API V2

关于android - 在 setContentView 找不到源 ~ android 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19030450/

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