我在eclipse上用1.6和2.2的测试过都能正常运行,然后用自己的XT800进行测试,失败。
我把源码放上,以及logcat里的报错信息,希望高手指点!package net.learn2develop.GoogleMaps;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.google.android.maps.MapView.LayoutParams;
import android.telephony.SmsMessage;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
public static final String PREF_FILE_NAME = "PrefFile";
String[] coordinates = new String[2];
String[] location = new String[2];
String temp;
Bundle bundle;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
// mapView.setSatellite(true); /**显示卫星视图
// mapView.setStreetView(true); /**显示街道视图
mc = mapView.getController();
bundle = getIntent().getExtras();
try {
if (bundle == null) {
temp = "40.849165,123.328739";
} else {
temp = bundle.getString("location");
}
location = temp.split(",");
} catch (NumberFormatException e) {
e.toString();
}
for (int i = 0; i < location.length; i++) {
coordinates = location;
}
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}class MapOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
// ---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
// ---add the er---
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
return true;
}
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
// ---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(), (int) event.getY());
/** 通过获取坐标来拿到地理名称加上坐标显示 **/
Geocoder geoCoder = new Geocoder(getBaseContext(),
Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6,
1);
String add = "";
if (addresses.size() > 0) {
for (int i = 0; i < addresses.get(0)
.getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i) + "\n"
+ p.getLatitudeE6() / 1E6 + ","
+ p.getLongitudeE6() / 1E6 + "\n";
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT)
.show();
} catch (IOException e) {
e.printStackTrace();
}
/**
* 通过已知的地名找出位置 Geocoder geoCoder = new
* Geocoder(getBaseContext(), Locale.getDefault()); try {
* List<Address> addresses = geoCoder.getFromLocationName(
* "empire state building", 5); String add = ""; if
* (addresses.size() > 0) { p = new GeoPoint( (int)
* (addresses.get(0).getLatitude() * 1E6), (int)
* (addresses.get(0).getLongitude() * 1E6)); mc.animateTo(p);
* mapView.invalidate(); } } catch (IOException e) {
* e.printStackTrace(); }
*/
return true;
} else
return false;
}
}
/** Called when the activity is first created. */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
MapController mc = mapView.getController();
switch (keyCode) {
case KeyEvent.KEYCODE_3:
mc.zoomIn();
break;
case KeyEvent.KEYCODE_1:
mc.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}package net.learn2develop.GoogleMaps;
import java.io.Serializable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SMSReceiver extends BroadcastReceiver implements Serializable {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.provider.Telephony.SMS_RECEIVED"
.equals(intent.getAction())) {
StringBuilder sb = new StringBuilder();
// 接收由SMS传过来的数据
Bundle bundle = intent.getExtras();
// 判断是否有数据
if (bundle != null) {
// 通过pdus可以获得接收到的所有短信消息
Object[] objArray = (Object[]) bundle.get("pdus");
/* 构建短信对象array,并依据收到的对象长度来创建array的大小 */
SmsMessage[] messages = new SmsMessage[objArray.length];
for (int i = 0; i < objArray.length; i++) {
messages = SmsMessage
.createFromPdu((byte[]) objArray);
}
/* 将送来的短信合并自定义信息于StringBuilder当中 */
for (SmsMessage currentMessage : messages) {
sb.append(currentMessage.getDisplayMessageBody());
}
}
Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
Intent mainIntent = new Intent(context, MapsActivity.class);
mainIntent.putExtra("location", sb.toString());
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainIntent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.GoogleMaps" android:versionCode="1"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MapsActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest><?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">
<com.google.android.maps.MapView
android:id="@+id/mapView" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:enabled="true"
android:clickable="true" android:apiKey="0XNxIh2B3i4Pkvl_csKw1UrAoEsywGp_5ngeJLg" />
<LinearLayout android:id="@+id/zoom" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>logcat:
03-06 12:13:34.268: ERROR/PackageReceiver Info(4215): packagename net.learn2develop.GoogleMaps action android.intent.action.PACKAGE_ADDED
03-06 12:13:34.479: ERROR/PackageReceiver Info(4215): sendingPackageinfo...
03-06 12:13:36.745: ERROR/dalvikvm(4495): could not disable core file generation for pid 4495, errno=1
03-06 12:13:36.971: ERROR/AndroidRuntime(4495): FATAL EXCEPTION: main
03-06 12:13:36.971: ERROR/AndroidRuntime(4495): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.learn2develop.GoogleMaps/net.learn2develop.GoogleMaps.MapsActivity}: java.lang.ClassNotFoundException: net.learn2develop.GoogleMaps.MapsActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/mnt/asec/net.learn2develop.GoogleMaps-1/pkg.apk]
03-06 12:13:36.971: ERROR/AndroidRuntime(4495): at android.app.ActivityThread.performLaunchActivity
我把源码放上,以及logcat里的报错信息,希望高手指点!package net.learn2develop.GoogleMaps;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.google.android.maps.MapView.LayoutParams;
import android.telephony.SmsMessage;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
public static final String PREF_FILE_NAME = "PrefFile";
String[] coordinates = new String[2];
String[] location = new String[2];
String temp;
Bundle bundle;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
// mapView.setSatellite(true); /**显示卫星视图
// mapView.setStreetView(true); /**显示街道视图
mc = mapView.getController();
bundle = getIntent().getExtras();
try {
if (bundle == null) {
temp = "40.849165,123.328739";
} else {
temp = bundle.getString("location");
}
location = temp.split(",");
} catch (NumberFormatException e) {
e.toString();
}
for (int i = 0; i < location.length; i++) {
coordinates = location;
}
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}class MapOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
// ---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
// ---add the er---
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
return true;
}
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
// ---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(), (int) event.getY());
/** 通过获取坐标来拿到地理名称加上坐标显示 **/
Geocoder geoCoder = new Geocoder(getBaseContext(),
Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6,
1);
String add = "";
if (addresses.size() > 0) {
for (int i = 0; i < addresses.get(0)
.getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i) + "\n"
+ p.getLatitudeE6() / 1E6 + ","
+ p.getLongitudeE6() / 1E6 + "\n";
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT)
.show();
} catch (IOException e) {
e.printStackTrace();
}
/**
* 通过已知的地名找出位置 Geocoder geoCoder = new
* Geocoder(getBaseContext(), Locale.getDefault()); try {
* List<Address> addresses = geoCoder.getFromLocationName(
* "empire state building", 5); String add = ""; if
* (addresses.size() > 0) { p = new GeoPoint( (int)
* (addresses.get(0).getLatitude() * 1E6), (int)
* (addresses.get(0).getLongitude() * 1E6)); mc.animateTo(p);
* mapView.invalidate(); } } catch (IOException e) {
* e.printStackTrace(); }
*/
return true;
} else
return false;
}
}
/** Called when the activity is first created. */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
MapController mc = mapView.getController();
switch (keyCode) {
case KeyEvent.KEYCODE_3:
mc.zoomIn();
break;
case KeyEvent.KEYCODE_1:
mc.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}package net.learn2develop.GoogleMaps;
import java.io.Serializable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SMSReceiver extends BroadcastReceiver implements Serializable {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.provider.Telephony.SMS_RECEIVED"
.equals(intent.getAction())) {
StringBuilder sb = new StringBuilder();
// 接收由SMS传过来的数据
Bundle bundle = intent.getExtras();
// 判断是否有数据
if (bundle != null) {
// 通过pdus可以获得接收到的所有短信消息
Object[] objArray = (Object[]) bundle.get("pdus");
/* 构建短信对象array,并依据收到的对象长度来创建array的大小 */
SmsMessage[] messages = new SmsMessage[objArray.length];
for (int i = 0; i < objArray.length; i++) {
messages = SmsMessage
.createFromPdu((byte[]) objArray);
}
/* 将送来的短信合并自定义信息于StringBuilder当中 */
for (SmsMessage currentMessage : messages) {
sb.append(currentMessage.getDisplayMessageBody());
}
}
Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
Intent mainIntent = new Intent(context, MapsActivity.class);
mainIntent.putExtra("location", sb.toString());
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainIntent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.GoogleMaps" android:versionCode="1"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MapsActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest><?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">
<com.google.android.maps.MapView
android:id="@+id/mapView" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:enabled="true"
android:clickable="true" android:apiKey="0XNxIh2B3i4Pkvl_csKw1UrAoEsywGp_5ngeJLg" />
<LinearLayout android:id="@+id/zoom" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>logcat:
03-06 12:13:34.268: ERROR/PackageReceiver Info(4215): packagename net.learn2develop.GoogleMaps action android.intent.action.PACKAGE_ADDED
03-06 12:13:34.479: ERROR/PackageReceiver Info(4215): sendingPackageinfo...
03-06 12:13:36.745: ERROR/dalvikvm(4495): could not disable core file generation for pid 4495, errno=1
03-06 12:13:36.971: ERROR/AndroidRuntime(4495): FATAL EXCEPTION: main
03-06 12:13:36.971: ERROR/AndroidRuntime(4495): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.learn2develop.GoogleMaps/net.learn2develop.GoogleMaps.MapsActivity}: java.lang.ClassNotFoundException: net.learn2develop.GoogleMaps.MapsActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/mnt/asec/net.learn2develop.GoogleMaps-1/pkg.apk]
03-06 12:13:36.971: ERROR/AndroidRuntime(4495): at android.app.ActivityThread.performLaunchActivity
解决方案 »
- SKIA源代码发现的两处内存泄露及解决方法!
- 问一个关于ContentProvider的问题
- android 触屏问题(出现偏差怎么回事)
- 怎么拿到ListView的item中的progressbar并更新进度
- Launcher修改以后编译错误,马上改回来还是编译错误
- Gallery图片索引
- android中json获取问题,求来大神啊
- github.com能ping通,但是https://github.com/wyouflf/xUtils网页打不开
- idea新建android项目出现的问题
- 有会做这个的大佬吗
- 编译android2.2 错误:undefined references to 'gDvmJit' follow.
- AutoCompleteTextView模糊提示
一下 方便以后追踪真相!
java.lang.ClassNotFoundException: net.learn2develop.GoogleMaps.MapsActivity in loader dalvik.system.PathClassLoader
没有对应的class