问题描述
这并不是指任何地方在我的code在所有。我该如何去获得到它的底部?
显示java.lang.NullPointerException
在com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
在com.google.android.maps.MapView.onDraw(MapView.java:494)
在android.view.View.draw(View.java:6739)
在android.view.ViewGroup.drawChild(ViewGroup.java:1648)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
在android.view.ViewGroup.drawChild(ViewGroup.java:1646)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
在android.view.View.draw(View.java:6742)
在android.widget.FrameLayout.draw(FrameLayout.java:352)
在android.view.ViewGroup.drawChild(ViewGroup.java:1648)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
在android.view.View.draw(View.java:6742)
在android.widget.FrameLayout.draw(FrameLayout.java:352)
在com.android.internal.policy.impl.PhoneWindow $ DecorView.draw(PhoneWindow.java:1872)
在android.view.ViewRoot.draw(ViewRoot.java:1422)
在android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
在android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:144)
在android.app.ActivityThread.main(ActivityThread.java:4937)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:521)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
在dalvik.system.NativeStart.main(本机方法)
下面是ItemizedOverlay
的绘制方法 公共无效画(油画画布,图形页面图形页面,布尔影子){
尝试 {
super.draw(帆布,图形页面,假);
如果(getMainOverlayArray()。大小()!= 0){
pfOverlayItem tempOver = NULL;
的for(int i = 0; I< getMainOverlayArray()的大小();我++){
。tempOver = getMainOverlayArray()获得(一);
布尔isMatch = FALSE;
如果(tempOver.getTitle()。等于(selectedName))
{
isMatch = TRUE;
}
如果(isMatch){
投影投影= MapView.getProjection()在;
点对点=新的点();
projection.toPixels(tempOver.getPoint(),点);
油漆背景=新的油漆();
background.setColor(Color.WHITE);
background.setAlpha(150);
RectF RECT =新RectF();
rect.set(point.x - 55,point.y +15,
point.x + 100,+ point.y 65);
canvas.drawRoundRect(矩形,5,5,背景);
漆文=新的油漆();
text.setAntiAlias(真正的);
text.setColor(Color.BLUE);
text.setTextSize(14);
text.setTypeface(Typeface.MONOSPACE);
canvas.drawText(tempOver.getTitle(),point.x -50,point.y + 30,文本);
canvas.drawText(tempOver.getTypeTextOut(),point.x -50,point.y + 45,文本);
canvas.drawText(tempOver.getdestination(),point.x -50,point.y + 60,文本);
}
}
}
}赶上(例外五){
Log.e(错误,问题工程视图,E);
e.printStackTrace();
}
}
我现在打印出堆栈跟踪并没有什么区别! : - (
有没有人有什么想法,可以帮助到这条底线?
编辑 - 最新code 28/11满级
私有类SitesOverlay扩展ItemizedOverlay< pfOverlayItem> {
私人列表< pfOverlayItem>项目=新的ArrayList< pfOverlayItem>();
私人PopupPanel面板=新PopupPanel(R.layout.popup);
私人MapLocation selectedMapLocation;
私有静态最终诠释CIRCLERADIUS = 2;
私人的ArrayList< pfOverlayItem> mOverlays =新的ArrayList< pfOverlayItem>();
公共SitesOverlay(){
超(空);
//超(boundCenter(defaultMarker));
//项= getMainOverlayArray();
//项目= mOverlays;
填充();
}
公共无效finishedLoading(){
填充();
}
@覆盖
保护pfOverlayItem createItem中(int i)以{
// Log.i(创建,标志);
返程(items.get(一));
}
公共无效的addItem(OverlayItem叠加){
overlay.setMarker(boundCenter(overlay.getMarker(0)));
items.add((pfOverlayItem)叠加);
//填充();
}
公共无效clearItems(){
runOnUiThread(新的Runnable(){
公共无效的run(){
items.clear();
myMapView.invalidate();
}
});
}
公共无效清除(){
mOverlays.clear();
myMapView.removeAllViews();
// numItems的= 0;
//解决方法与此类另一个bug:
// http://groups.google.com/group/android-developers/browse_thread/thread/38b11314e34714c3
setLastFocusedIndex(-1);
填充();
}
@覆盖
公共无效画(油画画布,图形页面图形页面,布尔影子){
super.draw(帆布,图形页面,假);
尝试 {
如果(getMainOverlayArray()。大小()!= 0){
pfOverlayItem tempOver = NULL;
的for(int i = 0; I< getMainOverlayArray()的大小();我++){
。tempOver = getMainOverlayArray()获得(一);
布尔isMatch = FALSE;
//Log.i("Selected名称,selectedName);
如果(tempOver.getTitle()。等于(selectedName))
{
isMatch = TRUE;
}
如果(isMatch){
投影投影= MapView.getProjection()在;
点对点=新的点();
projection.toPixels(tempOver.getPoint(),点);
油漆背景=新的油漆();
background.setColor(Color.WHITE);
background.setAlpha(150);
RectF RECT =新RectF();
rect.set(point.x - 50,point.y +15,
point.x + 90,+ point.y 50);
canvas.drawRoundRect(矩形,5,5,背景);
漆文=新的油漆();
text.setAntiAlias(真正的);
text.setColor(Color.BLUE);
text.setTextSize(14);
text.setTypeface(Typeface.MONOSPACE);
//canvas.drawRoundRect(rect,2,2,背景);
canvas.drawText(tempOver.getTitle()++ tempOver.getcallsign(),point.x -50,point.y + 30,文本);
canvas.drawText(tempOver.getdestination()++ tempOver.getdraft(),point.x -50,point.y + 45,文本);
}
}
}
}赶上(例外五){
Log.e(错误,问题工程视图,E);
e.printStackTrace();
}
}
@覆盖
受保护的布尔中的onTap(int i)以{
pfOverlayItem项目=的getItem(我);
如果(selectedName.equals(item.getTitle())){
//Toast.makeText(PlaneFinderMain.this,第二MOFO $ P $干燥综合征,3000).show();
尝试{
意图myIntent =新的意图(PlaneFinderMain.this,DetailActivity.class);
myIntent.putExtra(INT,我);
myIntent.putExtra(字符串,selectedName);
PlaneFinderMain.this.startActivity(myIntent);
}赶上(例外五){
Log.e(错误,无法启动,E);
}
}
currentadshex = item.getmmsi();
新GetRouteTask(item.getmmsi())执行()。
将selectedItem =我;
selectedName = item.getTitle();
selectedPlanePoint = item.getPoint();
的GeoPoint地理= item.getPoint();
点PT = myMapView.getProjection()toPixels(GEO,空)。
查看查看= panel.getView();
((TextView的)view.findViewById(R.id.reg))的setText(item.getTitle());
((TextView的)view.findViewById(R.id.flightno))的setText(item.getcallsign());
((TextView的)view.findViewById(R.id.route))的setText(item.getdestination());
((TextView的)view.findViewById(R.id.height))的setText(item.getdraft());
返回(真);
}
@覆盖
公共布尔的onTouchEvent(MotionEvent事件,图形页面图形页面){
如果(event.getAction()== MotionEvent.ACTION_DOWN){
如果(selectedPlanePoint!= NULL){
投影投影= MapView.getProjection()在;
点对点=新的点();
projection.toPixels(selectedPlanePoint,点);
点pointHit =新的点();
pointHit.x =(int)的event.getX();
pointHit.y =(int)的event.getY();
如果((point.x - pointHit.x)> -100安培;及(point.x - pointHit.x)< 70安培;及(point.y - pointHit.y)< -25安培;及(point.y - pointHit.y)> -95){
尝试{
意图myIntent =新的意图(PlaneFinderMain.this,DetailActivity.class);
myIntent.putExtra(INT,则selectedItem);
myIntent.putExtra(字符串,selectedName);
PlaneFinderMain.this.startActivity(myIntent);
}赶上(例外五){
Log.e(错误,无法启动,E);
}
}其他{
}
}
}
返回false;
}
@覆盖
公众诠释大小(){
返程(items.size());
}
公共无效addOverlay(OverlayItem O){
setLastFocusedIndex(-1);
填充();
}
}
其实这个问题是不是在你的ItemizedOverlay的实施,但在你的MapActivity的实施。你可以从一个类似的堆栈跟踪here在第42行的OverlayBundle被调用一个覆盖的draw()方法。这表明你添加到您MapView类的地方,一个空覆盖。
一些有用的提示:你应该通过取消注释$ C $的第一行肯定是通过一个可绘制你的超级构造函数(用于命中测试的)C你已经在那里:
公共SitesOverlay(){
//超(空);
超(boundCenter(defaultMarker));
//项= getMainOverlayArray();
//项目= mOverlays;
填充();
}
和可能不是在你的draw()方法调用super.draw()。
@覆盖
公共无效画(油画画布,图形页面图形页面,布尔影子){
//你为什么这样做,如果你自己画它以后。
super.draw(帆布,图形页面,假
您很有可能必须真正做到这两点。
编辑:试想想它,你一定要传递一个绘制你的超级构造函数,因为它是用于命中测试。修正上面的文字来反映这一点。
This does not refer to anywhere in my code at all. How do I go about getting to the bottom of it?
java.lang.NullPointerException
at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
at com.google.android.maps.MapView.onDraw(MapView.java:494)
at android.view.View.draw(View.java:6739)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
at android.view.View.draw(View.java:6742)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1872)
at android.view.ViewRoot.draw(ViewRoot.java:1422)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Here is the draw method of the ItemizedOverlay
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
try {
super.draw(canvas, mapView, false);
if (getMainOverlayArray().size() != 0){
pfOverlayItem tempOver = null;
for (int i = 0; i < getMainOverlayArray().size(); i++) {
tempOver = getMainOverlayArray().get(i);
boolean isMatch = false;
if (tempOver.getTitle().equals(selectedName))
{
isMatch = true;
}
if (isMatch){
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(tempOver.getPoint(), point);
Paint background = new Paint();
background.setColor(Color.WHITE);
background.setAlpha(150);
RectF rect = new RectF();
rect.set(point.x - 55, point.y +15,
point.x + 100, point.y + 65);
canvas.drawRoundRect(rect, 5, 5, background);
Paint text = new Paint();
text.setAntiAlias(true);
text.setColor(Color.BLUE);
text.setTextSize(14);
text.setTypeface(Typeface.MONOSPACE);
canvas.drawText(tempOver.getTitle() , point.x -50 , point.y + 30, text);
canvas.drawText(tempOver.getTypeTextOut(), point.x -50 , point.y + 45, text);
canvas.drawText(tempOver.getdestination(), point.x -50 , point.y + 60, text);
}
}
}
}catch (Exception e){
Log.e("Error", "Problem drawing view", e);
e.printStackTrace();
}
}
I now print out the stacktrace and no difference! :-(
Does anyone have any ideas that could help get to the bottom of this?
EDIT - Latest code 28/11 FULL CLASS
private class SitesOverlay extends ItemizedOverlay<pfOverlayItem> {
private List<pfOverlayItem> items = new ArrayList<pfOverlayItem>();
private PopupPanel panel=new PopupPanel(R.layout.popup);
private MapLocation selectedMapLocation;
private static final int CIRCLERADIUS = 2;
private ArrayList<pfOverlayItem> mOverlays = new ArrayList<pfOverlayItem>();
public SitesOverlay() {
super(null);
//super(boundCenter(defaultMarker));
//items = getMainOverlayArray();
//items = mOverlays;
populate();
}
public void finishedLoading(){
populate();
}
@Override
protected pfOverlayItem createItem(int i) {
// Log.i("CREATE","MARKER");
return (items.get(i));
}
public void addItem(OverlayItem overlay) {
overlay.setMarker(boundCenter(overlay.getMarker(0)));
items.add((pfOverlayItem) overlay);
//populate();
}
public void clearItems(){
runOnUiThread(new Runnable() {
public void run() {
items.clear();
myMapView.invalidate();
}
});
}
public void clear() {
mOverlays.clear();
myMapView.removeAllViews();
//numItems = 0;
// Workaround for another bug with this class:
// http://groups.google.com/group/android-developers/browse_thread/thread/38b11314e34714c3
setLastFocusedIndex(-1);
populate();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, false);
try {
if (getMainOverlayArray().size() != 0){
pfOverlayItem tempOver = null;
for (int i = 0; i < getMainOverlayArray().size(); i++) {
tempOver = getMainOverlayArray().get(i);
boolean isMatch = false;
//Log.i("Selected Name",selectedName);
if (tempOver.getTitle().equals(selectedName))
{
isMatch = true;
}
if (isMatch){
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(tempOver.getPoint(), point);
Paint background = new Paint();
background.setColor(Color.WHITE);
background.setAlpha(150);
RectF rect = new RectF();
rect.set(point.x - 50, point.y +15,
point.x + 90, point.y + 50);
canvas.drawRoundRect(rect, 5, 5, background);
Paint text = new Paint();
text.setAntiAlias(true);
text.setColor(Color.BLUE);
text.setTextSize(14);
text.setTypeface(Typeface.MONOSPACE);
//canvas.drawRoundRect(rect, 2, 2, background);
canvas.drawText(tempOver.getTitle() + " " + tempOver.getcallsign(), point.x -50 , point.y + 30, text);
canvas.drawText(tempOver.getdestination() + " " + tempOver.getdraft(), point.x -50 , point.y + 45, text);
}
}
}
}catch (Exception e){
Log.e("Error", "Problem drawing view", e);
e.printStackTrace();
}
}
@Override
protected boolean onTap(int i) {
pfOverlayItem item = getItem(i);
if (selectedName.equals(item.getTitle())){
//Toast.makeText(PlaneFinderMain.this, "SECOND MOFO PRESS", 3000).show();
try{
Intent myIntent = new Intent(PlaneFinderMain.this, DetailActivity.class);
myIntent.putExtra( "int", i);
myIntent.putExtra( "string", selectedName );
PlaneFinderMain.this.startActivity(myIntent);
}catch (Exception e){
Log.e("Error", "Cannot launch", e);
}
}
currentadshex = item.getmmsi();
new GetRouteTask(item.getmmsi()).execute();
selectedItem = i;
selectedName = item.getTitle();
selectedPlanePoint = item.getPoint();
GeoPoint geo=item.getPoint();
Point pt=myMapView.getProjection().toPixels(geo, null);
View view=panel.getView();
((TextView)view.findViewById(R.id.reg)).setText(item.getTitle());
((TextView)view.findViewById(R.id.flightno)).setText(item.getcallsign());
((TextView)view.findViewById(R.id.route)).setText(item.getdestination());
((TextView)view.findViewById(R.id.height)).setText(item.getdraft());
return (true);
}
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
if (selectedPlanePoint != null){
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(selectedPlanePoint, point);
Point pointHit = new Point();
pointHit.x=(int)event.getX();
pointHit.y=(int)event.getY();
if ((point.x - pointHit.x) >-100 && (point.x - pointHit.x) <70 && (point.y - pointHit.y) < -25 && (point.y - pointHit.y) > -95){
try{
Intent myIntent = new Intent(PlaneFinderMain.this, DetailActivity.class);
myIntent.putExtra( "int", selectedItem);
myIntent.putExtra( "string", selectedName );
PlaneFinderMain.this.startActivity(myIntent);
}catch (Exception e){
Log.e("Error", "Cannot launch", e);
}
}else{
}
}
}
return false;
}
@Override
public int size() {
return (items.size());
}
public void addOverlay(OverlayItem o){
setLastFocusedIndex(-1);
populate();
}
}
Actually the problem is not in the implementation of your ItemizedOverlay, but in the implementation of your MapActivity. As you can see from a similar stack trace here at line 42 the OverlayBundle is calling the draw() method of an Overlay. This points to a null Overlay that you added to your mapView somewhere.
Some helpful hints:You should definitely pass a drawable to your super constructor (used of hit-testing) by uncommenting the first line of code you already have in there:
public SitesOverlay() {
//super(null);
super(boundCenter(defaultMarker));
//items = getMainOverlayArray();
//items = mOverlays;
populate();
}
and potentially not call super.draw() in your draw() method.
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
// why do you do this if you paint it yourself later on.
super.draw(canvas, mapView, false
Most likely you will have to actually do both.
Edit: Come to think of it you should definitely pass a drawable to your super constructor as it is used for hit-testing. Amended the text above to reflect that.
这篇关于Android地图NullPointerException异常ItemizedOverlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!