我从谷歌下载项目示例(LocationUpdates.zip,http://developer.android.com/training/location/retrieve-current.html)。当我运行它时,它显示如下异常,但并非总是如此:
08-10 16:10:34.119: W/System.err(26914): java.lang.NumberFormatException: Invalid int: ""
08-10 16:10:34.127: W/System.err(26914): at java.lang.Integer.invalidInt(Integer.java:138)
08-10 16:10:34.127: W/System.err(26914): at java.lang.Integer.parseInt(Integer.java:359)
08-10 16:10:34.127: W/System.err(26914): at java.lang.Integer.parseInt(Integer.java:332)
08-10 16:10:34.127: W/System.err(26914): at java.util.Calendar.getHwFirstDayOfWeek(Calendar.java:807)
08-10 16:10:34.127: W/System.err(26914): at java.util.Calendar.<init>(Calendar.java:745)
08-10 16:10:34.127: W/System.err(26914): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:338)
08-10 16:10:34.127: W/System.err(26914): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:325)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1Time.getDecodedObject(ASN1Time.java:44)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1UTCTime.decode(ASN1UTCTime.java:82)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1Choice.decode(ASN1Choice.java:308)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.BerInputStream.readSequence(BerInputStream.java:554)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.DerInputStream.readSequence(DerInputStream.java:105)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1Sequence.decode(ASN1Sequence.java:40)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.BerInputStream.readSequence(BerInputStream.java:554)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.DerInputStream.readSequence(DerInputStream.java:105)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1Sequence.decode(ASN1Sequence.java:40)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.BerInputStream.readSequence(BerInputStream.java:554)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.DerInputStream.readSequence(DerInputStream.java:105)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1Sequence.decode(ASN1Sequence.java:40)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.asn1.ASN1Type.decode(ASN1Type.java:91)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.provider.cert.X509CertImpl.<init>(X509CertImpl.java:102)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.provider.cert.X509CertFactoryImpl.getCertificate(X509CertFactoryImpl.java:656)
08-10 16:10:34.127: W/System.err(26914): at org.apache.harmony.security.provider.cert.X509CertFactoryImpl.engineGenerateCertificate(X509CertFactoryImpl.java:109)
08-10 16:10:34.127: W/System.err(26914): at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:195)
08-10 16:10:34.135: W/System.err(26914): at com.google.android.gms.common.GooglePlayServicesUtil.a(Unknown Source)
08-10 16:10:34.135: W/System.err(26914): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
08-10 16:10:34.135: W/System.err(26914): at com.google.android.gms.internal.p.connect(Unknown Source)
08-10 16:10:34.135: W/System.err(26914): at com.google.android.gms.location.LocationClient.connect(Unknown Source)
08-10 16:10:34.135: W/System.err(26914): at com.example.android.location.MainActivity.onStart(MainActivity.java:197)
08-10 16:10:34.135: W/System.err(26914): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
08-10 16:10:34.135: W/System.err(26914): at android.app.Activity.performStart(Activity.java:4475)
08-10 16:10:34.135: W/System.err(26914): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
08-10 16:10:34.135: W/System.err(26914): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-10 16:10:34.135: W/System.err(26914): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-10 16:10:34.135: W/System.err(26914): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-10 16:10:34.135: W/System.err(26914): at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 16:10:34.135: W/System.err(26914): at android.os.Looper.loop(Looper.java:137)
08-10 16:10:34.135: W/System.err(26914): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-10 16:10:34.135: W/System.err(26914): at java.lang.reflect.Method.invokeNative(Native Method)
08-10 16:10:34.135: W/System.err(26914): at java.lang.reflect.Method.invoke(Method.java:511)
08-10 16:10:34.135: W/System.err(26914): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-10 16:10:34.135: W/System.err(26914): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
08-10 16:10:34.135: W/System.err(26914): at dalvik.system.NativeStart.main(Native Method)
代码在这里:
public class MainActivity extends FragmentActivity implements
LocationListener,
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
// A request to connect to Location Services
private LocationRequest mLocationRequest;
// Stores the current instantiation of the location client in this object
private LocationClient mLocationClient;
......
}
......
public void onStart() {
Log.i(TAG, "onStart of MainActivity");
super.onStart();
/*
* Connect the client. Don't re-start any requests here;
* instead, wait for onResume()
*/
Log.i(TAG, "connect() of LocationClient begin");
mLocationClient.connect();
Log.i(TAG, "connect() of LocationClient finish");
}
例外是因为这句话:
mLocationClient.connect();
当我尝试新建 MimeMessage 时,还有另一个项目,它抛出完全相同的异常:NumberFormatException:
MimeMessage message = new MimeMessage(session);
事实上,在我的项目中,即使我没有操作数字/时间相关的变量,也有很多场景会抛出这种异常。这个人跟我有同样的问题。 java InputStreamReader中的Android错误仅适用于华为手机
我为这个例外挣扎了很多天。我不知道为什么。希望一些android专家可以帮助我。谢谢大家。我的手机是华为Ascend D1 dual。