我已经玩了一段时间了,我希望有比我更聪明的人能帮上忙。我的老板给了我一个学习开发Android应用程序的机会,而我正在努力解决这个问题。我需要构建几个具有多个活动的应用程序,但似乎无法超越这一点。我确定这是我的编码中的一个问题,但是有这么多不同的方式做事情,我在这一点上有点困惑。
我正在构建一个应用程序,打开一个页面上的两个按钮的主要活动。一个是关闭按钮,效果很好。我希望单击“下一步”按钮打开设置为“我的校园”位置的mapActivity。我不是一个正在做项目的学生,我只是在一个社区大学工作。;-)
真正奇怪的是,完全相同的google.maps代码本身就可以正常工作。我只是无法在不崩溃的情况下获得打开Activity的按钮。
这是我的manifest.xml,main.xml,my main.java,Map.java和map.xml。你能评论一下,给我指个方向吗?
提前谢谢你,戴夫
这里有两个错误:
11-21 14:50:58.968: W/dalvikvm(437): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-21 14:50:58.978: E/AndroidRuntime(437): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=edu.mtsac.mapproject.MAP }这表示未找到该活动,但我可以在我的源文件中以及此处的清单中看到它:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.mtsac.mapproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="@string/app_name"
android:name=".Main" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- map activity -->
<activity
android:label="Map"
android:name=".Map" >
<intent-filter >
<action android:name="edu.mtsac.mapproject.MAP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>我的Main.xml和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"
android:orientation="vertical" >
<Button
android:id="@+id/mapBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Map" />
</RelativeLayout>Map.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0jevUfyLD_b1Eikgpm_mo7KVDspzhPJdRDDaxEw"
android:clickable="true"
android:enabled="true" />
</LinearLayout>the Main.java
package edu.mtsac.mapproject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button mapBtn = (Button) findViewById(R.id.mapBtn);
mapBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Main.this, Map.class));
}
});
Button closeBtn = (Button) findViewById(R.id.closeBtn);
closeBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
};// end onCreate()
}最后是Map.java
package edu.mtsac.mapproject;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class Map extends MapActivity {
MapController mc;
GeoPoint p;
MapView mapview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapview = (MapView) findViewById(R.id.mapView);
mapview.displayZoomControls(true);
mapview.setBuiltInZoomControls(true);
mapview.setSatellite(true);
mc = mapview.getController();
String coord[] = { "34.047517", "-117.847050" };
double lat = Double.parseDouble(coord[0]);
double lng = Double.parseDouble(coord[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapview.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}发布于 2011-11-22 07:44:55
我在您的清单中没有看到任何已注册来处理此操作的活动,edu.mtsac.mapproject.MAP。我假设当您调用以下代码时会发生异常:
startActivity(new Intent("edu.mtsac.mapproject.MAP"));看起来您可能正在尝试启动Map活动,而您不需要为其指定Action。只要像这样做就行了:
startActivity(new Intent(this, Map.class));您可能想要阅读此doc on intents以了解这里到底发生了什么,以及您应该如何使用这些类。
发布于 2011-11-22 07:42:47
在"map“按钮中,单击implementation创建一个动作为"edu.mtsac.mapproject.MAP"的意图。由于您的清单的意图过滤器正在查找操作"android.intent.action.MAP",因此它不会解析为您的活动。
我相信你被明确的意图和含蓄的意图搞糊涂了。显式意图使用您要使用的活动的特定名称,而隐式意图仅定义您想要完成的操作。
要使其正常工作,请更改映射按钮以启动清单中的操作。
发布于 2011-11-22 07:49:52
在您的Main.java中,尝试使用以下代码:
Button mapBtn = (Button) findViewById(R.id.mapBtn);
mapBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Main.this, Map.class));
}
});https://stackoverflow.com/questions/8220061
复制相似问题