我正在为钛创建一个deezer模块。

可视化登录消息时出现问题。

这是我的DeezerAndroidModule.java(或其中很大一部分)

@Kroll.module(name="DeezerAndroidModule", id="deezer.android")
public class DeezerAndroidModuleModule extends KrollModule
{
    private static final String TAG = "DeezerAndroidModuleModule";
        private final String APP_ID = "xxx";
        private final static String[] PERMISSIONS = new String[]{"basic_access","offline_access","email"};
    private DeezerInterface deezerInterface;
    private     DeezerConnect connection;
        {...}
    @Kroll.method
    public void loginDeezer()
    {

        connection.authorize(deezerInterface, PERMISSIONS, new ReconnectDialogHandler());

    }
        @Kroll.method @Kroll.getProperty
    public String userId()
    {

        DeezerRequest request = new DeezerRequest( "/user/me" );
        String result = null;
        try {
            result = connection.requestSync( request );
        }//try
        catch( MalformedURLException ex ) {

        }//catch
        catch( IOException ex ) {

        }//catch
        catch (OAuthException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DeezerError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return result;

    }
        {...}
    class ReconnectDialogHandler implements DialogListener {

        @Override
        public void onComplete(final Bundle values) {
            SessionStore sessionStore = new SessionStore();
            sessionStore.save( connection, deezerInterface );

        }//met

        @Override
        public void onDeezerError(final DeezerError deezerError) {

        }//met

        @Override
        public void onError(final DialogError dialogError) {

        }//met

        @Override
        public void onCancel() {

        }//met

        @Override
        public void onOAuthException(OAuthException oAuthException) {

        }//met


    }


问题是,当我调用loginDeezer()函数时,应用程序将抛出通用的Java Exception而不提示登录视图...

这是一个logcat标题

W/System.err( 6737): java.lang.NullPointerException
W/System.err( 6737):    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:412)
W/System.err( 6737):    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl$HttpsEngine.makeConnection(HttpsURLConnectionImpl.java:378)
W/System.err( 6737):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018)
W/System.err( 6737):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)
W/System.err( 6737):    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:258)
W/System.err( 6737):    at com.deezer.sdk.b.a(Unknown Source)
W/System.err( 6737):    at com.deezer.sdk.b.a(Unknown Source)
W/System.err( 6737):    at com.deezer.sdk.DeezerConnectImpl.requestSync(Unknown Source)
W/System.err( 6737):    at deezer.android.DeezerAndroidModuleModule.userId(DeezerAndroidModuleModule.java:84)
W/System.err( 6737):    at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
W/System.err( 6737):    at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:64)
W/System.err( 6737):    at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:835)
W/System.err( 6737):    at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1059)
W/System.err( 6737):    at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err( 6737):    at android.os.Looper.loop(Looper.java:130)
W/System.err( 6737):    at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)


我的代码有什么不正确的地方?

最佳答案

借助XGouchet,我仅使用Activity就解决了这个问题:

在DeezerModule中

@Kroll.method
public void loginDeezer()
{
    TiApplication appContext = TiApplication.getInstance();
    Activity act = appContext.getCurrentActivity();
    Intent myIntent = new Intent(act, DeezerInterface.class);
    act.startActivity(myIntent);
}


并且DeezerInterface活动类为this

07-27 14:50