我正在尝试使用 Google Api 的库运行 android 应用程序,并且在将地址输入到输入字段时进行调试时收到失败启动错误。
这是错误:http ://s1278.beta.photobucket.com/user/cetmrw791346/media/wdyl_zps08bbe17f.png.html?sort=3&o=0
和
以下是相关文件:
AWhereDoYouLive.java
package com.example.wheredoyoulive;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class AWhereDoYouLive extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final AlertDialog.Builder adb = new AlertDialog.Builder(this);
final EditText addressfield = (EditText) findViewById(R.id.address);
final Button button = (Button) findViewById(R.id.launchmap);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
// Perform action on click
String address = addressfield.getText().toString();
address = address.replace(' ', '+');
Intent geoIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));
startActivity(geoIntent);
} catch (Exception e) {
AlertDialog ad = adb.create();
ad.setMessage("Failed to Launch");
ad.show();
}
}
});
}
}
主.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please enter your home address."
/>
<EditText
android:id="@+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoText="true"
/>
<Button
android:id="@+id/launchmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Map"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlocking Android, Chapter 1."
/>
</LinearLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wheredoyoulive"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/icon" >
<activity android:label="@string/app_name"
android:name="com.example.wheredoyoulive.AWhereDoYouLive">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<users-permission android:name="android.permission.INTERNET" />
</manifest>