0

我从谷歌下载项目示例(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。

4

3 回答 3

0

您可能需要声明LocationClient mLocationClient; 为类变量

于 2013-08-10T16:40:35.233 回答
0

您似乎已经声明了 mLocationClient 变量,但是您在调用另一个方法(mLLocationClient.connect() 方法)之前没有对其进行初始化。

尝试将此添加到您的代码中。

mLocationClient = new LocationClient();

这将在调用该方法之前初始化变量。

如果这已经解决了,那么请知道在您调用 mLocationClient.connect() 时,如果 mLLocationClient 为空,它将给您一个错误。因此,您需要设置一个条件,如果 mLLocationClient 在连接之前为空,则设置该条件。例如

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");

    //Checks to see if LocationClient is not set and then sets it
    setUpLocationClientIfNull();
    mLocationClient.connect();
    Log.i(TAG, "connect() of LocationClient finish");

}

//And now the method to set up mLocationClient if its null
private void setUpLocationClientIfNull() {
   if (mLocationClient == null) {
       mLocationClient = new LocationClient(this, this, this);
   } 
}

这确保在调用 mLLocationClient.connect() 方法之前设置了 mLocationClient。

于 2013-08-29T01:31:35.253 回答
0

服务器用于 SSL 的证书不完全遵循 X.509 标准,并且 Apache Harmony 证书解析器中断,因为它期望 ASN.1 UTCTime 并且它创建一个不同的类型。

如果您无法替换服务器证书,则需要使用您自己的 SSL 握手实现。

于 2015-11-25T11:37:48.727 回答