在主要活動即時在佈局的Android按鈕點擊應用崩潰
<?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">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
gotomap.java
public class gotomap extends Activity {
public gotomap(){}
getcoordinates loc;
double lati,longi;
private GoogleMap googleMap;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loc = new getcoordinates(this); //getlocation
if(loc.canGetLocation())
{
lati = loc.getLatitude();
longi = loc.getLongitude();
Toast.makeText(this, "Your Location is - \nLat: " + lati + "\nLong: " + longi, Toast.LENGTH_LONG).show();
}
final LatLng locate = new LatLng(lati ,longi);
setContentView(R.layout.gotomap);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().
findFragmentById(R.id.map)).getMap();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
使用片段使用意圖作爲
btnlocate.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, gotomap.class);
startActivity(intent);
MainActivity.this.finish();
}
});
在gotomap.xml林
日誌
02-02 10:16:13.986: I/Process(30530): Sending signal. PID: 30530 SIG: 9
02-02 10:16:17.883: V/Monotype(30591): SetAppTypeFace- try to flip, app = com.example.locato
02-02 10:16:17.885: V/Monotype(30591): Typeface getFontPathFlipFont - systemFont = default#default
02-02 10:16:17.891: V/Monotype(30591): SetAppTypeFace- try to flip, app = com.example.locato
02-02 10:16:17.891: V/Monotype(30591): Typeface getFontPathFlipFont - systemFont = default#default
02-02 10:16:17.943: D/OpenGLRenderer(30591): Render dirty regions requested: true
02-02 10:16:17.963: D/Atlas(30591): Validating map...
02-02 10:16:18.041: I/OpenGLRenderer(30591): Initialized EGL, version 1.4
02-02 10:16:18.041: W/OpenGLRenderer(30591): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
02-02 10:16:18.069: D/OpenGLRenderer(30591): Enabling debug mode 0
02-02 10:16:19.237: I/System.out(30591): intent>>>>>>>>Intent { cmp=com.example.locato/.gotomap }
02-02 10:16:19.238: D/AndroidRuntime(30591): Shutting down VM
02-02 10:16:19.239: E/AndroidRuntime(30591): FATAL EXCEPTION: main
02-02 10:16:19.239: E/AndroidRuntime(30591): Process: com.example.locato, PID: 30591
02-02 10:16:19.239: E/AndroidRuntime(30591): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.locato/com.example.locato.gotomap}; have you declared this activity in your AndroidManifest.xml?
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1761)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.Activity.startActivityForResult(Activity.java:3778)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.Activity.startActivityForResult(Activity.java:3739)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.Activity.startActivity(Activity.java:4049)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.Activity.startActivity(Activity.java:4017)
02-02 10:16:19.239: E/AndroidRuntime(30591): at com.example.locato.MainActivity$1.onClick(MainActivity.java:24)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.view.View.performClick(View.java:4756)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.view.View$PerformClick.run(View.java:19761)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.os.Handler.handleCallback(Handler.java:739)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.os.Handler.dispatchMessage(Handler.java:95)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.os.Looper.loop(Looper.java:135)
02-02 10:16:19.239: E/AndroidRuntime(30591): at android.app.ActivityThread.main(ActivityThread.java:5253)
02-02 10:16:19.239: E/AndroidRuntime(30591): at java.lang.reflect.Method.invoke(Native Method)
02-02 10:16:19.239: E/AndroidRuntime(30591): at java.lang.reflect.Method.invoke(Method.java:372)
02-02 10:16:19.239: E/AndroidRuntime(30591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
02-02 10:16:19.239: E/AndroidRuntime(30591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
斷點甚而不去發送活動,,, 應用程序崩潰時調用的意圖...... 請做要緊......
後日志語句 –
添加到您的清單中刪除'公共gotomap(){}''從類gotomap'。你不應該不必要地創建構造函數。 – SMR
崩潰與哪個異常?請將堆棧跟蹤添加到問題中。 – Timo