适用于Android的deezer appcelerator模块

时间:2013-08-22 12:27:07

标签: android titanium appcelerator titanium-modules 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)

我的代码中哪些不正确?

1 个答案:

答案 0 :(得分:1)

我解决了这个问题,感谢XGouchet,只是使用了Activities:

在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