googel app class crash on startActivity(intent)

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

googel app class crash on startActivity(intent)

Postby maulik6758 » Wed Apr 27, 2011 2:51 pm

MainActivity.java
===============

package com.sampleapp;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Paint.Align;
import android.os.Bundle;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.BaseDialogListener;
import com.facebook.android.BaseRequestListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.SessionEvents;
import com.facebook.android.SessionStore;
import com.facebook.android.Util;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.SessionEvents.AuthListener;
import com.facebook.android.SessionEvents.LogoutListener;
import com.sampleapp.MainActivity.iTab.OnTabClickListener;
import com.sampleapp.MainActivity.iTab.TabMember;

public class MainActivity extends Activity
{



boolean Select = false;
private Facebook mFacebook;
private String[] mPermissions;
private Activity mActivity;
private Button mPostButton;
private Handler mHandler;
private AsyncFacebookRunner mAsyncRunner;
private TextView mText;
private SessionListener mSessionListener = new SessionListener();
public static final String APP_ID = "175729095772478";

public static class iTab extends ImageView
{
private Paint mPaint;
private Paint mActiveTextPaint;
private Paint mInactiveTextPaint;
private ArrayList<TabMember> mTabMembers;
private int mActiveTab;
private OnTabClickListener mOnTabClickListener = null;

public iTab( Context context, AttributeSet attrs ) {
super(context, attrs);

mTabMembers = new ArrayList<MainActivity.iTab.TabMember>();

mPaint = new Paint();
mActiveTextPaint = new Paint();
mInactiveTextPaint = new Paint();

mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(0xFFFFFF00);

mActiveTextPaint.setTextAlign(Align.CENTER);
mActiveTextPaint.setTextSize(12);
mActiveTextPaint.setColor(0xFFFFFFFF);
mActiveTextPaint.setFakeBoldText(true);

mInactiveTextPaint.setTextAlign(Align.CENTER);
mInactiveTextPaint.setTextSize(12);
mInactiveTextPaint.setColor(0xFF999999);
mInactiveTextPaint.setFakeBoldText(true);

mActiveTab = 0;

}

@Override
protected void onDraw(Canvas canvas)
{
Log.d(TAG, "iTab onDraw start");
super.onDraw(canvas);

Rect r = new Rect();
this.getDrawingRect(r);

// Calculate how many pixels each tab can use
int singleTabWidth = r.right
/ (mTabMembers.size() != 0 ? mTabMembers.size() : 1);

Log.d(TAG, "iTab: SingleTabWidth: " + singleTabWidth);

// Draw the background
canvas.drawColor(0xFF000000);
mPaint.setColor(0xFF434343);
canvas.drawLine(r.left, r.top + 1, r.right, r.top + 1, mPaint);

int color = 46;

for (int i = 0; i < 24; i++)
{
mPaint.setARGB(255, color, color, color);
canvas.drawRect(r.left, r.top + i + 1, r.right, r.top + i + 2,
mPaint);
color--;
}

// Draw each tab
for (int i = 0; i < mTabMembers.size(); i++)
{
TabMember tabMember = mTabMembers.get(i);

Bitmap icon = BitmapFactory.decodeResource(getResources(),
tabMember.getIconResourceId());
Bitmap iconColored = Bitmap.createBitmap(icon.getWidth(), icon
.getHeight(), Bitmap.Config.ARGB_8888);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG
| Paint.FILTER_BITMAP_FLAG);
Canvas iconCanvas = new Canvas();
iconCanvas.setBitmap(iconColored);

if (mActiveTab == i)
{
p.setShader(new LinearGradient(0, 0, icon.getWidth(), icon
.getHeight(), 0xFFFFFFFF, 0xFF54C7E1,
Shader.TileMode.CLAMP));
} else
{
p.setShader(new LinearGradient(0, 0, icon.getWidth(), icon
.getHeight(), 0xFFA2A2A2, 0xFF5F5F5F,
Shader.TileMode.CLAMP));
}

iconCanvas.drawRect(0, 0, icon.getWidth(), icon.getHeight(), p);

for (int x = 0; x < icon.getWidth(); x++)
{
for (int y = 0; y < icon.getHeight(); y++)
{
if ((icon.getPixel(x, y) & 0xFF000000) == 0)
{
iconColored.setPixel(x, y, 0x00000000);
}
}
}

// Calculate Tab Image Position
int tabImgX = singleTabWidth * i
+ (singleTabWidth / 2 - icon.getWidth() / 2);

// Active Tab will be drawn in a different way
if (mActiveTab == i)
{
mPaint.setARGB(37, 255, 255, 255);
canvas.drawRoundRect(new RectF(r.left + singleTabWidth * i
+ 3, r.top + 3, r.left + singleTabWidth * (i + 1)
- 3, r.bottom - 2), 5, 5, mPaint);
canvas.drawBitmap(iconColored, tabImgX, r.top + 5, null);
canvas.drawText(tabMember.getText(), singleTabWidth * i
+ (singleTabWidth / 2), r.bottom - 2,
mActiveTextPaint);
} else
{
canvas.drawBitmap(iconColored, tabImgX, r.top + 5, null);
canvas.drawText(tabMember.getText(), singleTabWidth * i
+ (singleTabWidth / 2), r.bottom - 2,
mInactiveTextPaint);
}
}

Log.d(TAG, "iTab onDraw finished");
}

@Override
public boolean onTouchEvent(MotionEvent motionEvent)
{
Rect r = new Rect();
this.getDrawingRect(r);
float singleTabWidth = r.right
/ (mTabMembers.size() != 0 ? mTabMembers.size() : 1);

int pressedTab = (int) ((motionEvent.getX() / singleTabWidth) - (motionEvent
.getX() / singleTabWidth) % 1);

mActiveTab = pressedTab;

if (this.mOnTabClickListener != null)
{
this.mOnTabClickListener.onTabClick(mTabMembers.get(pressedTab)
.getId());
}

this.invalidate();

return super.onTouchEvent(motionEvent);
}

void addTabMember(TabMember tabMember)
{
mTabMembers.add(tabMember);
}

void setOnTabClickListener(OnTabClickListener onTabClickListener)
{
mOnTabClickListener = onTabClickListener;
}

public static class TabMember
{
protected int mId;
protected String mText;
protected int mIconResourceId;

TabMember( int Id, String Text, int iconResourceId ) {
mId = Id;
mIconResourceId = iconResourceId;
mText = Text;
}

public int getId()
{
return mId;
}

public String getText()
{
return mText;
}

public int getIconResourceId()
{
return mIconResourceId;
}

public void setText(String Text)
{
mText = Text;
}

public void setIconResourceId(int iconResourceId)
{
mIconResourceId = iconResourceId;
}
}

public static interface OnTabClickListener
{
public abstract void onTabClick(int tabId);
}
}

public static class iRelativeLayout extends RelativeLayout
{
private Paint mPaint;
private Rect mRect;

public iRelativeLayout( Context context, AttributeSet attrs ) {
super(context, attrs);

mRect = new Rect();
mPaint = new Paint();

mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(0xFFCBD2D8);
}

@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);

canvas.drawColor(0xFFC5CCD4);

this.getDrawingRect(mRect);

for (int i = 0; i < mRect.right; i += 7)
{
canvas.drawRect(mRect.left + i, mRect.top, mRect.left + i + 2,
mRect.bottom, mPaint);
}

}
}

public static final String TAG = "SAMPLEAPP";

private static final int TAB_HIGHLIGHT = 1;
private static final int TAB_CHAT = 2;
private static final int TAB_LOOPBACK = 3;
private static final int TAB_REDO = 4;
private static final int TAB_New = 5;
private iTab mTabs;
private LinearLayout mTabLayout_One;
private LinearLayout mTabLayout_Two;
private LinearLayout mTabLayout_Three;
private LinearLayout mTabLayout_Four;
private LinearLayout mTabLayout_Five;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (APP_ID == null)
{
Util
.showAlert(
this,
"Warning",
"Facebook Applicaton ID must be "
+ "specified before running this example: see Example.java");
}

setContentView(R.layout.main);


mText = (TextView) MainActivity.this.findViewById(R.id.txt);
mPostButton = (Button) findViewById(R.id.postButton);

mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);

// SessionStore.restore(mFacebook, this);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
mActivity = MainActivity.this;
mPermissions = new String[] {};
mHandler = new Handler();
SessionEvents.addAuthListener(mSessionListener);
SessionEvents.addLogoutListener(mSessionListener);

mPostButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
mFacebook.dialog(MainActivity.this, "feed",
new SampleDialogListener());
}
});
mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE
: View.INVISIBLE);

TextView txtview = (TextView) findViewById(R.id.txtview);
txtview.setTextSize(17);
mTabs = (iTab) this.findViewById(R.id.Tabs);
mTabLayout_One = (LinearLayout) this.findViewById(R.id.TabLayout_One);
mTabLayout_Two = (LinearLayout) this.findViewById(R.id.TabLayout_Two);
mTabLayout_Three = (LinearLayout) this.findViewById(R.id.TabLayout_Three);
mTabLayout_Four = (LinearLayout) this.findViewById(R.id.TabLayout_Four);
mTabLayout_Five = (LinearLayout) this.findViewById(R.id.TabLayout_Five);

mTabs.addTabMember(new TabMember(TAB_HIGHLIGHT, "Home",
R.drawable.homebtn));
mTabs.addTabMember(new TabMember(TAB_CHAT, "Today Deal",
R.drawable.todaysdealbtn));
mTabs.addTabMember(new TabMember(TAB_LOOPBACK, "Spread Word",
R.drawable.spreadthewordbtn));
mTabs.addTabMember(new TabMember(TAB_REDO, "Advertise",
R.drawable.advertisebtn));
mTabs.addTabMember(new TabMember(TAB_New, "Contact",
R.drawable.contactusbtn));

mTabLayout_One.setVisibility(View.VISIBLE);
mTabLayout_Two.setVisibility(View.GONE);
mTabLayout_Three.setVisibility(View.GONE);
mTabLayout_Four.setVisibility(View.GONE);
mTabLayout_Five.setVisibility(View.GONE);
Select = false;
mTabs.setOnTabClickListener(new OnTabClickListener()
{
@Override
public void onTabClick(int tabId)
{
Select = true;
if (tabId == TAB_HIGHLIGHT)
{
Select = false;
mTabLayout_One.setVisibility(View.VISIBLE);
mTabLayout_Two.setVisibility(View.GONE);
mTabLayout_Three.setVisibility(View.GONE);
mTabLayout_Four.setVisibility(View.GONE);
mTabLayout_Five.setVisibility(View.GONE);


} else if (tabId == TAB_CHAT)
{
Select=true;
mTabLayout_One.setVisibility(View.GONE);
mTabLayout_Two.setVisibility(View.VISIBLE);
mTabLayout_Three.setVisibility(View.GONE);
mTabLayout_Four.setVisibility(View.GONE);
mTabLayout_Five.setVisibility(View.GONE);


if( Select == true)
{
Intent intent = new Intent();
intent.setClass(MainActivity.this,GPSLocatorActivity.class);
startActivity(intent);
}





} else if (tabId == TAB_LOOPBACK)
{
Select = false;
mTabLayout_One.setVisibility(View.GONE);
mTabLayout_Two.setVisibility(View.GONE);
mTabLayout_Three.setVisibility(View.VISIBLE);
mTabLayout_Four.setVisibility(View.GONE);
mTabLayout_Five.setVisibility(View.GONE);

AlertDialog.Builder alertbox = new AlertDialog.Builder(
MainActivity.this);

alertbox
.setMessage("Help us spread the word. By clicking twitter or facebook links you can make us more popular and we can get more advertises and better deals.");

alertbox.setPositiveButton("Facebook",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton)
{
System.out.println("Session");

if (mFacebook.isSessionValid())
{
System.out.println("validSession");
mFacebook.dialog(MainActivity.this,
"feed",
new SampleDialogListener());
} else
{
System.out.println("invalidSession");
mFacebook.authorize(mActivity,
mPermissions,
new LoginDialogListener());
System.out
.println("InvalidSession Done");
}
System.out.println("out1");
}

});
System.out.println("out3");
alertbox.setNeutralButton("Twitter",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton)
{

Intent intent = new Intent(
Intent.ACTION_SEND);
intent
.putExtra(Intent.EXTRA_TEXT,
"@stealthcopter Example tweet from android application");
intent.setType("application/twitter");
try
{
startActivity(Intent.createChooser(
intent, null));
} catch (ActivityNotFoundException e)
{

Toast.makeText(getApplicationContext(),
"Twidroid not found.",
Toast.LENGTH_SHORT).show();
}
}
});

alertbox.setNegativeButton("Cancel",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton)
{
// Toast.makeText(getApplicationContext(),
// "'Cancel' button clicked",
// Toast.LENGTH_SHORT).show();
}
});

// display box
alertbox.show();
System.out.println("out2");

} else if (tabId == TAB_REDO)
{
Select = false;
mTabLayout_One.setVisibility(View.GONE);
mTabLayout_Two.setVisibility(View.GONE);
mTabLayout_Three.setVisibility(View.GONE);
mTabLayout_Four.setVisibility(View.VISIBLE);
mTabLayout_Five.setVisibility(View.GONE);
} else if (tabId == TAB_New)
{
Select = false;
mTabLayout_One.setVisibility(View.GONE);
mTabLayout_Two.setVisibility(View.GONE);
mTabLayout_Three.setVisibility(View.GONE);
mTabLayout_Four.setVisibility(View.GONE);
mTabLayout_Five.setVisibility(View.VISIBLE);

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("application/twitter"); // use from live device
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { "contact@todaysfreebie.com" });
try
{
startActivity(Intent.createChooser(i,
"Select email application."));
} catch (Exception e)
{
Log.i("Hi", "Error");
}

}
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
System.out.println("onActivityResult");
mFacebook.authorizeCallback(requestCode, resultCode, data);
}

public class SampleAuthListener implements AuthListener
{
public void onAuthSucceed()
{
System.out.println("onAuthSucceed !!");
// mText.setText("You have logged in! ");
// mPostButton.setVisibility(View.VISIBLE);
System.out.println("onAuthSucceed Done");
}

public void onAuthFail(String error)
{
System.out.println("onAuthFail");
mText.setText("Login Failed: " + error);
}
}

public class SampleLogoutListener implements LogoutListener
{
public void onLogoutBegin()
{
System.out.println("onLogoutBegin");
mText.setText("Logging out...");
}

public void onLogoutFinish()
{
System.out.println("onLogoutFinish");
mText.setText("You have logged out! ");
mPostButton.setVisibility(View.INVISIBLE);
}
}

public class SampleRequestListener extends BaseRequestListener
{

public void onComplete(final String response, final Object state)
{
try
{
System.out.println("onComplete");
// process the response here: executed in background thread
Log.d("Facebook-Example", "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String name = json.getString("name");

// then post the processed result back to the UI thread
// if we do not do this, an runtime exception will be generated
// e.g. "CalledFromWrongThreadException: Only the original
// thread that created a view hierarchy can touch its views."
MainActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
mText.setText("Hello there, " + name + "!");
}
});
} catch (JSONException e)
{
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e)
{
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
}

public class SampleUploadListener extends BaseRequestListener
{

public void onComplete(final String response, final Object state)
{
try
{
System.out.println("SampleUploadListener");
// process the response here: (executed in background thread)
Log.d("Facebook-Example", "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String src = json.getString("src");

// then post the processed result back to the UI thread
// if we do not do this, an runtime exception will be generated
// e.g. "CalledFromWrongThreadException: Only the original
// thread that created a view hierarchy can touch its views."
MainActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
mText
.setText("Hello there, photo has been uploaded at \n"
+ src);
}
});
} catch (JSONException e)
{
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e)
{
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
}

public class WallPostRequestListener extends BaseRequestListener
{

public void onComplete(final String response, final Object state)
{
/*System.out.println("WallPostRequestListener");
Log.d("Facebook-Example", "Got response: " + response);
String message = "<empty>";
try
{
JSONObject json = Util.parseJson(response);
message = json.getString("message");
} catch (JSONException e)
{
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e)
{
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
final String text = "Your Wall Post: " + message;
MainActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
mText.setText(text);
}
});*/
}
}

public class WallPostDeleteListener extends BaseRequestListener
{

public void onComplete(final String response, final Object state)
{
if (response.equals("true"))
{
Log.d("Facebook-Example", "Successfully deleted wall post");
MainActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
// mDeleteButton.setVisibility(View.INVISIBLE);
mText.setText("Deleted Wall Post");
}
});
} else
{
Log.d("Facebook-Example", "Could not delete wall post");
}
}
}

public class SampleDialogListener extends BaseDialogListener
{

public void onComplete(Bundle values)
{
System.out.println("Post - Id");
final String postId = values.getString("post_id");
if (postId != null)
{
Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
mAsyncRunner.request(postId, new WallPostRequestListener());

} else
{
Log.d("Facebook-Example", "No wall post made");
}
}
}

// -----------------------Login Button Code ---------------

private final class LoginDialogListener implements DialogListener
{
public void onComplete(Bundle values)
{
System.out.println("LoginDialogListener");
SessionEvents.onLoginSuccess();

System.out.println(">>>>>>>>>>>>>Success");
mFacebook.dialog(MainActivity.this, "feed",
new SampleDialogListener());

}

public void onFacebookError(FacebookError error)
{
System.out.println("Error Login");
SessionEvents.onLoginError(error.getMessage());
}

public void onError(DialogError error)
{
SessionEvents.onLoginError(error.getMessage());
}

public void onCancel()
{
SessionEvents.onLoginError("Action Canceled");
}
}

@SuppressWarnings("unused")
private class LogoutRequestListener extends BaseRequestListener
{
public void onComplete(String response, final Object state)
{
// callback should be run in the original thread,
// not the background thread
mHandler.post(new Runnable()
{
public void run()
{
SessionEvents.onLogoutFinish();
}
});
}
}

private class SessionListener implements AuthListener, LogoutListener
{
public void onAuthSucceed()
{
System.out.println("onAuthSucceed2");
SessionStore.save(mFacebook, MainActivity.this);
}

public void onAuthFail(String error)
{
System.out.println("AuthFail");
}

public void onLogoutBegin()
{
System.out.println("onLoginBegin");
}

public void onLogoutFinish()
{
SessionStore.clear(MainActivity.this);
}
}

}

===============================================================================================

GPSLocatorActivity
================

package com.sampleapp;


import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

import android.location.Geocoder;
import android.location.Address;

import com.google.android.maps.Overlay;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;

import java.util.List;
import java.util.Locale;
import java.io.IOException;

import android.os.Bundle;
import android.util.Log;

public class GPSLocatorActivity extends MapActivity {
private MapView mapView;
private MapController mapController;

private LocationManager locationManager;
private LocationListener locationListener;

// private static final int latitudeE6 = 37985339;
//private static final int longitudeE6 = 23716735;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapmain);

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

locationListener = new GPSLocationListener(this);

locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,1,1,locationListener);


mapView = (MapView) findViewById(R.id.mapView);

// enable Street view by default
mapView.setStreetView(true);

// enable to show Satellite view
// mapView.setSatellite(true);

// enable to show Traffic on map
// mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapController = mapView.getController();
mapController.setZoom(16);


}

@Override
protected boolean isRouteDisplayed() {
return false;
}

private class GPSLocationListener implements LocationListener
{
GPSLocatorActivity gpsLoc;
public GPSLocationListener(GPSLocatorActivity gpsloc) {
gpsLoc = gpsloc;
}
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));

System.out.println("OnLocationChange :: "+ point.getLatitudeE6());
/* Toast.makeText(getBaseContext(),
"Latitude: " + location.getLatitude() +
" Longitude: " + location.getLongitude(),
Toast.LENGTH_SHORT).show(); */


// add marker
Drawable drawable = gpsLoc.getResources().getDrawable(R.drawable.red);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, gpsLoc);
StringBuilder result = new StringBuilder();
try{
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> addresses =
gcd.getFromLocation(location.getLatitude(), location.getLongitude(),100);

if (addresses.size() > 0) {

for(int i = 0; i < addresses.size(); i++)
{
Address address = addresses.get(i);
int maxIndex = address.getMaxAddressLineIndex();
for (int x = 0; x <= maxIndex; x++ ){
result.append(address.getAddressLine(x));
break;
}
//result.append(address.getLocality());
// result.append(",");
// result.append(address.getPostalCode());
// result.append("\n\n");
}
}
}
catch(IOException ex){
Log.i("Hi", "Hi");

}



List<Overlay> mapOverlays = mapView.getOverlays();
OverlayItem overlayitem = new OverlayItem(point, "Hello", "I'm at "+result+" !");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);

MapController mapController = mapView.getController();

mapController.animateTo(point);
mapController.setZoom(16);
}
}

public String ConvertPointToLocation(GeoPoint point) {
String address = "";
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6,
point.getLongitudeE6() / 1E6, 1);

if (addresses.size() > 0) {
for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}
catch (IOException e) {
e.printStackTrace();
}

return address;
}

@Override
public void onProviderDisabled(String provider) {
/*Toast.makeText(getBaseContext(),
"GPS Disabled",
Toast.LENGTH_SHORT).show();*/
}

@Override
public void onProviderEnabled(String provider) {
/*Toast.makeText(getBaseContext(),
"GPS Enabled",
Toast.LENGTH_SHORT).show();*/

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
/*Toast.makeText(getBaseContext(),
"Status",
Toast.LENGTH_SHORT).show();*/
}
}

class MapOverlay extends Overlay
{
private GeoPoint pointToDraw;

public void setPointToDraw(GeoPoint point) {
pointToDraw = point;
}

public GeoPoint getPointToDraw() {
return pointToDraw;
}

@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);

// convert point to pixels
Point screenPts = new Point();
mapView.getProjection().toPixels(pointToDraw, screenPts);

// add marker
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.red);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null); // 24 is the height of image
return true;
}
}
}

===============================================================================================

mapmain.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"
>
<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="0Vy8telYm-Lv2juDesOUO5rwWuG2VM2SpiD8vmA"
/>
</LinearLayout>

===============================================================================================

main.xml
========

<?xml version="1.0" encoding="utf-8"?>
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="com.sampleapp.MainActivity$iRelativeLayout" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#C5CCD4FF">
<LinearLayout android:id="@+id/TabLayout_One"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_above="@+id/Tabs" android:background="@drawable/mainpage">

</LinearLayout>

<LinearLayout android:id="@+id/TabLayout_Two"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_above="@+id/Tabs" android:background="@drawable/mainpage">
<!--<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">

</ScrollView>
--></LinearLayout>
<LinearLayout android:id="@+id/TabLayout_Three"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_above="@+id/Tabs" android:background="@drawable/mainpage">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal">

<!--<com.facebook.android.LoginButton
android:id="@+id/login" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Facebook"
android:layout_margin="30dp" />
-->

<!--<Button android:id="@+id/button1" android:layout_width="wrap_content" android:text="Click Me" android:layout_height="wrap_content"></Button>

--><Button android:id="@+id/uploadButton" android:text="@string/upload"
android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingRight="20dp"
android:paddingLeft="20dp" android:layout_margin="20dp" />

<Button android:id="@+id/requestButton" android:text="@string/request"
android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingRight="20dp"
android:paddingLeft="20dp" android:layout_margin="20dp" />


<Button android:id="@+id/postButton" android:text="@string/post"
android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingRight="20dp"
android:paddingLeft="20dp" android:layout_margin="20dp" />

<Button android:id="@+id/deletePostButton" android:text="@string/delete"
android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingRight="20dp"
android:paddingLeft="20dp" android:layout_margin="20dp" />
</LinearLayout>

</ScrollView>
</LinearLayout>
<LinearLayout android:id="@+id/TabLayout_Four"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_above="@+id/Tabs" android:background="@drawable/mainnavpage1">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout android:id="@+id/TabLayout_Four"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:visibility="visible" android:layout_above="@+id/Tabs">
<TextView android:id="@+id/txtview" android:textColor="@android:color/black"
android:paddingLeft="25px" android:paddingTop="15px"
android:paddingRight="25px" android:paddingBottom="15px"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="The biggest difference between managers and leaders is the way they motivate the people who work or follow them, and this sets the tone for most other aspects of what they do.
Many people, by the way, are both. They have management jobs, but they realize that you cannot buy hearts, especially to follow them down a difficult path, and so act as leaders too.
Managers have subordinates By definition, managers have subordinates - unless their title is honorary and given as a mark of seniority, in which case the title is a misnomer and their power over others is other than formal authority.
Authoritarian, transactional style Managers have a position of authority vested in them by the company, and their subordinates work for them and largely do as they are told. Management style is transactional, in that the manager
tells the subordinate what to do, and the subordinate does this not because they are a blind robot, but because they have been promised a reward" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
<LinearLayout android:id="@+id/TabLayout_Five"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_above="@+id/Tabs" android:background="@drawable/mainpage">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout android:id="@+id/TabLayout_Four"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:visibility="visible" android:layout_above="@+id/Tabs">

</RelativeLayout>
</ScrollView>
</LinearLayout>
<view class="com.sampleapp.MainActivity$iTab" android:id="@+id/Tabs"
android:layout_width="fill_parent" android:layout_height="57px"
android:layout_alignParentBottom="true" />
</view>

=================================================================================================

Androidmanifest.xml
==================

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sampleapp"
android:versionCode="1"
android:versionName="1.0">



<application android:icon="@drawable/todaysicon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />

<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<activity android:name="com.facebook.android.Example"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>

<activity android:name=".SplashScreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".GPSLocatorActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>



</application>
</manifest>
maulik6758
Freshman
Freshman
 
Posts: 4
Joined: Wed Apr 13, 2011 7:55 pm

Top

Re: googel app class crash on startActivity(intent)

Postby mathias.lin » Thu Apr 28, 2011 3:03 pm

A lot of unformatted code, I doubt anybody will read it. You should rather post the logfile with the error (adb logcat).
User avatar
mathias.lin
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Tue Aug 11, 2009 4:21 am
Location: Guangzhou, China

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests