[英]MapActivity launching from OnClickListener
Just started working with android and ran into a small problem. 刚开始使用android并遇到一个小问题。 I am have a TabActivity that is loading 3 other Activity classes. 我有一个TabActivity,正在加载其他3个Activity类。 This works great. 这很好。 I then have a button on the other Activity classes that I would like to launch a MapActivity. 然后,在要启动MapActivity的其他Activity类上有一个按钮。 When I do that I keep getting a Force Close. 当我这样做时,我会一直保持力量闭合。
I googled but I cannot figure out if it is the manifest file or something else. 我用谷歌搜索,但无法弄清楚它是清单文件还是其他文件。 The idea is the tabs are showing location information and you click a button to plot it on the map and get directions. 想法是标签显示位置信息,然后单击按钮将其绘制在地图上并获取方向。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_tab);
... Button btnMap = (Button) findViewById(R.id.btnLaunchMap); ...按钮btnMap =(按钮)findViewById(R.id.btnLaunchMap); btnMap.setOnClickListener(mMapListener); btnMap.setOnClickListener(mMapListener); } }
private OnClickListener mMapListener = new OnClickListener() { public void onClick(View v) { Intent mapIntent = new Intent(getApplicationContext(),LocationMap.class); 私人OnClickListener mMapListener = new OnClickListener(){public void onClick(View v){Intent mapIntent = new Intent(getApplicationContext(),LocationMap.class); startActivity(mapIntent); startActivity(mapIntent);
} }; };
If I launch any other activity it works but not launching the mapactivity. 如果我启动任何其他活动,则可以正常运行,但不能启动mapactivity。 If I take the mapactivity class and put it in a new project it works. 如果我使用mapactivity类并将其放在新项目中,那么它将起作用。
My manifest 我的清单
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Splash"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Locations"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"></activity>
<activity android:name=".LocationNewYork"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".LocationChicago"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"></activity>
<activity android:name=".LocationSeattle"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"></activity>
<activity android:name=".LocationMap"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</activity>
<uses-library android:name="com.google.android.maps"/>
</application>
thougths? 思想?
<action android:name="android.intent.action.MAIN" />
inside of the mapactivity's instance ACTIVITY field in the Manifest file does it. 清单文件中mapactivity的实例ACTIVITY字段内部执行此操作。
So if you have a MapActivity named QMap, the following code in the Manifest actually works: 因此,如果您有一个名为QMap的MapActivity,那么清单中的以下代码实际上可以工作:
<activity android:name=".QMap"><action android:name="android.intent.action.MAIN" /></activity>
Hope it helped 希望能有所帮助
I had the same problem, wanted to launch map activity from an other activity over onClick-event, the problem was: errors in the MapActivity 我遇到了同样的问题,想通过onClick-event从其他活动启动地图活动,问题是:MapActivity中的错误
If you are using eclipse try to run "debug as" without setting any breakpoints 如果您使用的是eclipse,请尝试在不设置任何断点的情况下运行“ debug as”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.