致命異常:主要 了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.bugs3.munishgupta.cabup/com.bugs3.munishgupta.cabup.WannaHier} :java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access $ 600(ActivityThread .java:123) at android.app.ActivityThread $ h.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Loop er.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method .java:511) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:825) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592) at dalvik .system.NativeStart.main(本機方法) 引起:java.lang.NullPointerException at com.bugs3.munishgupta.cabup.WannaHier.onCreate(WannaHier.java:44) at android.app.Activity.performCreate(Activity .java:4465) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051) at android.a pp.ActivityThread.performLaunchActivity(ActivityThread.java:1920) ...... 11多個執行代碼時,我收到以下錯誤
想Hier.java
package com.bugs3.munishgupta.cabup; import java.util.concurrent.ExecutionException; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.content.Intent; import android.location.Location; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener; import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; public class WannaHier extends Activity { GoogleMap map; Intent info; String mob,lat,lon,title=null; Bundle b; Button btVCab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wanna_hier); info = getIntent(); b = info.getExtras(); mob = b.getString("mob"); btVCab=(Button) findViewById(R.id.btVCab); map=((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); map.setMyLocationEnabled(true); lat=Double.toString(map.getMyLocation().getLatitude()); lon=Double.toString(map.getMyLocation().getLongitude()); map.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { // TODO Auto-generated method stub try { title=marker.getTitle().toString(); request(title,lat,lon,mob); } catch(Exception e) { Toast.makeText(getApplicationContext(), "Please turn on your location", Toast.LENGTH_LONG).show(); } return false; } }); map.setOnMyLocationChangeListener(new OnMyLocationChangeListener() { @Override public void onMyLocationChange(Location location) { // TODO Auto-generated method stub JSONGetRequest jRequest = JSONGetRequest .getSingleInstance(WannaHier.this); try { String url = (Tags.url + "op=update&query=update requestpick set carNo='" +title+ "',latitude='" + lat + "', longitude='" + lon +"'where cust_mob='"+ mob +"'").replaceAll( " ", "%20"); JSONObject json = jRequest.execute(url).get(); if (json.getInt("success")==1) { Log.d("Requested Successfully!", json.toString()); } else { Log.d("Request failed!", json.getString("message")); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btVCab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub JSONGetRequest jRequest = JSONGetRequest .getSingleInstance(WannaHier.this); try { String url = (Tags.url + "op=select&query=select * from driverloc") .replaceAll(" ", "%20"); JSONObject json = jRequest.execute(url).get(); if (json.getInt("success")==1) { Log.d("Requested Successfully!", json.toString()); JSONArray js=json.getJSONArray("entities"); try{ for(int co=js.length(), i=0; i<co;i++){ json=js.getJSONObject(i); title=json.getString("carNo"); lat=json.getString("latitude"); lon=json.getString("longitude"); map.addMarker(new MarkerOptions() .position(new LatLng(Double.parseDouble(lat),Double.parseDouble(lon))) .title(title)); } } catch(JSONException e) { e.printStackTrace(); } } else { Log.d("Request failed!", json.getString("message")); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Toast.makeText(getApplicationContext(), "Please Turn on your location and click on view cabs", Toast.LENGTH_LONG).show(); } public void request(String title, String lat, String lon, String mob) { JSONGetRequest jRequest = JSONGetRequest .getSingleInstance(WannaHier.this); try { String url = (Tags.url + "op=insert&query=insert into requestpick values ('" +title+ "','" + lat + "','" + lon +"','"+ mob +"')").replaceAll( " ", "%20"); JSONObject json = jRequest.execute(url).get(); if (json.getInt("success")==1) { Log.d("Requested Successfully!", json.toString()); } else { Log.d("Request failed!", json.getString("message")); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); JSONGetRequest jRequest = JSONGetRequest .getSingleInstance(WannaHier.this); try { String url = (Tags.url + "op=delete&query=delete from requestpick where cust_mob='" + mob +"'").replaceAll(" ", "%20"); JSONObject json = jRequest.execute(url).get(); if (json.getInt("success")==1) { Log.d("Requested Successfully!", json.toString()); } else { Log.d("Request failed!", json.getString("message")); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } finish(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.wanna_hier, menu); return true; } }
Profile.java
package com.bugs3.munishgupta.cabup; import com.bugs3.munishgupta.cabup.R; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class Profile extends Activity { Button obhier, obshare, obsettings; String mob,carno,table; Intent info; Bundle b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.profile); obhier=(Button) findViewById(R.id.btnHier); obshare=(Button) findViewById(R.id.btnShare); obsettings=(Button) findViewById(R.id.btnSetting); info = getIntent(); b = info.getExtras(); table=b.getString("table"); if((carno=b.getString("carno"))!=null) { Toast.makeText(getApplicationContext(), carno, Toast.LENGTH_SHORT).show(); obhier.setVisibility(View.INVISIBLE); } else { obshare.setVisibility(View.INVISIBLE); } obshare.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent wshare=new Intent(Profile.this,WannaShare.class); mob = b.getString("mob"); wshare.putExtra("mob", mob); wshare.putExtra("carno", carno); wshare.putExtra("table", table); startActivity(wshare); } }); obhier.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent whier=new Intent(Profile.this,WannaHier.class); mob = b.getString("mob"); whier.putExtra("mob", mob); whier.putExtra("table", table); startActivity(whier); } }); obsettings.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent isetting = new Intent(Profile.this,ChangeSetting.class); if(b.getString("mob")!=null) { mob = b.get("mob").toString(); isetting.putExtra("mob", mob); isetting.putExtra("table", table); } startActivity(isetting); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.profile, menu); return true; } }
指示線44 @'WannaHier' –