logcat的
04-15 23:03:12.796: E/AndroidRuntime(1281): FATAL EXCEPTION: main
04-15 23:03:12.796: E/AndroidRuntime(1281): Process: com.mobeelity.android.googlemapversion2, PID: 1281
04-15 23:03:12.796: E/AndroidRuntime(1281): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobeelity.android.googlemapversion2/com.mobeelity.android.googlemapversion2.MainActivity}: java.lang.NullPointerException
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.os.Handler.dispatchMessage(Handler.java:102)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.os.Looper.loop(Looper.java:136)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-15 23:03:12.796: E/AndroidRuntime(1281): at java.lang.reflect.Method.invokeNative(Native Method)
04-15 23:03:12.796: E/AndroidRuntime(1281): at java.lang.reflect.Method.invoke(Method.java:515)
04-15 23:03:12.796: E/AndroidRuntime(1281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-15 23:03:12.796: E/AndroidRuntime(1281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-15 23:03:12.796: E/AndroidRuntime(1281): at dalvik.system.NativeStart.main(Native Method)
04-15 23:03:12.796: E/AndroidRuntime(1281): Caused by: java.lang.NullPointerException
04-15 23:03:12.796: E/AndroidRuntime(1281): at com.mobeelity.android.googlemapversion2.MainActivity.onCreate(MainActivity.java:45)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.Activity.performCreate(Activity.java:5231)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-15 23:03:12.796: E/AndroidRuntime(1281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-15 23:03:12.796: E/AndroidRuntime(1281): ... 11 more
04-15 23:08:12.976: I/Process(1281): Sending signal. PID: 1281 SIG: 9
SPLASH SCREEN.JAVA
package com.mobeelity.android.googlemapversion2;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
//import android.view.Window;
//import android.view.WindowManager;
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash_screen);
Thread logoTimer = new Thread() {
public void run() {
try {
int logoTimer = 0;
while (logoTimer < 3000) {
sleep(100);
logoTimer = logoTimer + 100;
}
startActivity(new Intent("MainActivity"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
finish();
}
}
};
logoTimer.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.splash_screen, menu);
return true;
}
}
MAIN.JAVA(GPS)
package com.mobeelity.android.googlemapversion2;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.location.Location;
import android.location.LocationManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
private int userIcon;
private GoogleMap theMap;
private LocationManager locMan;
private Marker userMarker;
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userIcon = R.drawable.yellow_point;
if (theMap == null) {
// map not instantiated yet
}
theMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.the_map)).getMap();
if (theMap != null) {
// ok - proceed
}
theMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
updatePlaces();
}
private void updatePlaces() {
// update location
locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location lastLoc = locMan
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
double lat = lastLoc.getLatitude();
double lng = lastLoc.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
if (userMarker != null)
userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions().position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 3000,
null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.send_report) {
startActivity(new Intent(getBaseContext(), Report.class));
}
if (item.getItemId() == R.id.get_navigation) {
locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location lastLoc = locMan
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
double lat = lastLoc.getLatitude();
double lng = lastLoc.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
String Text = "Moving to your location..."
+ "\nYour current location is: " + "\nLatitude : " + lat
+ "\nLongitude : " + lng;
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
.show();
if (userMarker != null)
userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng).title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng),
3000, null);
return true;
}
return super.onOptionsItemSelected(item);
// switch (item.getItemId()) {
// case R.id.send_report:
// Intent i = new Intent(
// "com.mobeelity.android.googlemapversion2.Report");
// startActivity(i);
// return true;
//
// case R.id.get_navigation:
// locMan = (LocationManager)
// getSystemService(Context.LOCATION_SERVICE);
// Location lastLoc = locMan
// .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
//
// double lat = lastLoc.getLatitude();
// double lng = lastLoc.getLongitude();
//
// LatLng lastLatLng = new LatLng(lat, lng);
// String Text = "Moving to your location..."
// + "\nYour current location is: " + "\nLatitude : " + lat
// + "\nLongitude : " + lng;
// Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
// .show();
//
// if (userMarker != null)
// userMarker.remove();
//
// userMarker = theMap.addMarker(new MarkerOptions()
// .position(lastLatLng).title("You are here")
// .icon(BitmapDescriptorFactory.fromResource(userIcon))
// .snippet("Your last recorded location"));
//
// theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng),
// 3000, null);
// return true;
//
// default:
// return super.onOptionsItemSelected(item);
// }
}
}
REPORT.JAVA
package com.mobeelity.android.googlemapversion2;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class Report extends Activity {
TextView textimsi, textbrand, textmodel, textimei, textversion,
textnetwork, textdatetime, textlat, textlng;
TelephonyManager tel;
Spinner spinner1;
RadioGroup radiofreq, radiodoor;
RadioButton radioquency, radioinout;
Button btnSubmit;
private LocationManager locMan;
@SuppressLint("SimpleDateFormat")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_report);
locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location lastLoc = locMan
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
textimsi = (TextView) findViewById(R.id.textView4);
textmodel = (TextView) findViewById(R.id.textView5);
textbrand = (TextView) findViewById(R.id.textView7);
textimei = (TextView) findViewById(R.id.textView9);
textversion = (TextView) findViewById(R.id.textView11);
textnetwork = (TextView) findViewById(R.id.textView13);
textdatetime = (TextView) findViewById(R.id.textView15);
radiofreq = (RadioGroup) findViewById(R.id.radioFrequency);
radiodoor = (RadioGroup) findViewById(R.id.radioDoor);
textlat = (TextView) findViewById(R.id.textView19);
textlng = (TextView) findViewById(R.id.textView20);
textlat.setText(Double.toString(lastLoc.getLatitude()));
textlng.setText(Double.toString(lastLoc.getLongitude()));
// String textlat = getIntent().getExtras().getString("LONGITUDE");
// String textlng = getIntent().getExtras().getString("LATITUDE");
tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
textimsi.setText(tel.getSubscriberId().toString());
textimei.setText(tel.getDeviceId().toString());
textnetwork.setText(tel.getNetworkOperatorName().toString());
textbrand.setText(Build.BRAND.toString());
textmodel.setText(Build.MODEL.toString());
textversion.setText(Build.VERSION.RELEASE.toString());
addListenerOnButton();
addListenerOnSpinnerItemSelection();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MMM:dd_hh:mm:ss");
String currentDateandTime = sdf.format(new Date());
textdatetime.setText(currentDateandTime.toString());
}
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
}
// get the selected dropdown list value
public void addListenerOnButton() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
btnSubmit = (Button) findViewById(R.id.button1);
btnSubmit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// get selected radio button from radioGroup
int selectedfrequencyId = radiofreq.getCheckedRadioButtonId();
int selectedindooroutdoorId = radiodoor
.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioquency = (RadioButton) findViewById(selectedfrequencyId);
radioinout = (RadioButton) findViewById(selectedindooroutdoorId);
Toast.makeText(
Report.this,
"Send Report : " + "\nIMSI Number : "
+ String.valueOf(textimsi.getText())
+ "\nPhone Brand : "
+ String.valueOf(textbrand.getText())
+ "\nPhone Model : "
+ String.valueOf(textmodel.getText())
+ "\nIMEI Number : "
+ String.valueOf(textimei.getText())
+ "\nOS Version : "
+ String.valueOf(textversion.getText())
+ "\n-----Coordinates-----" + "\nLatitude : "
+ String.valueOf(textlat.getText())
+ "\nLongitude : "
+ String.valueOf(textlng.getText())
+ "\nCurrent Technology : "
+ String.valueOf(textnetwork.getText())
+ "\nDate/Time : "
+ String.valueOf(textdatetime.getText())
+ "\nFrequency : "
+ radioquency.getText().toString()
+ "\nIndoor/Outdoor : "
+ radioinout.getText().toString()
+ "\nProblem : "
+ String.valueOf(spinner1.getSelectedItem()),
Toast.LENGTH_SHORT).show();
sendEmail();
}
});
}
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = { "canillojohnterence18@gmail.com" };
String[] CC = { "annjuan18@gmail.com" + "michael.manlac@docomopacific.net" };
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Problem Report");
emailIntent.putExtra(
Intent.EXTRA_TEXT,
"Send Report : " + "\nIMSI Number : "
+ String.valueOf(textimsi.getText())
+ "\nPhone Brand : "
+ String.valueOf(textbrand.getText())
+ "\nPhone Model : "
+ String.valueOf(textmodel.getText())
+ "\nIMEI Number : "
+ String.valueOf(textimei.getText())
+ "\nOS Version : "
+ String.valueOf(textversion.getText())
+ "\n-----Coordinates-----"
+ "\nLatitude : "
+ String.valueOf(textlat.getText())
+ "\nLongitude : "
+ String.valueOf(textlng.getText())
+ "\nCurrent Technology : "
+ String.valueOf(textnetwork.getText())
+ "\nDate/Time : "
+ String.valueOf(textdatetime.getText())
+ "\nFrequency : " + radioquency.getText().toString()
+ "\nIndoor/Outdoor : "
+ radioinout.getText().toString() + "\nProblem : "
+ String.valueOf(spinner1.getSelectedItem()));
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Report.this, "There is no email client installed.",
Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.report, menu);
return true;
}
}
CUSTOMONITEMSELECTEDLISTENER.JAVA
package com.mobeelity.android.googlemapversion2;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
public class CustomOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
Toast.makeText(
parent.getContext(),
"Selected Problem : "
+ parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
这是我的表现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobeelity.android.googlemapversion2"
android:versionCode="1"
android:versionName="1.0.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission
android:name="com.mobeelity.android.googlemapversion2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mobeelity.android.googlemapversion2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_docomo_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.mobeelity.android.googlemapversion2.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="com.mobeelity.android.googlemapversion2.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" >
</meta-data>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD5Ipf5p-BWuewuTIR6Lz46EsuuVgOEDME" />
<activity
android:name="com.mobeelity.android.googlemapversion2.Report"
android:label="@string/title_activity_report" >
</activity>
</application>
</manifest>
答案 0 :(得分:0)
试试这个..
可能会得到ActivityNotFoundException
改变这个..
startActivity(new Intent("MainActivity"));
到
startActivity(new Intent(SplashScreen.this,MainActivity.class));
答案 1 :(得分:0)
new Intent("MainActivity");
您传递的是Activity名称而不是Action,String参数用于表示隐式/自定义意图操作。例如:android.intent.action.VIEW
尝试使用Activity类
startActivity(new Intent(SplashScreen.this,MainActivity.class));
MainActivity类中的问题
地图为空
添加此
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
theMap = mapFrag.getMap();
if (theMap != null) {
theMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
updatePlaces();
}