首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android集成库应用

android集成库应用
EN

Stack Overflow用户
提问于 2011-12-19 02:32:46
回答 2查看 284关注 0票数 0

我正在尝试将一个开源应用集成到我的android应用中。我已经将开源应用程序作为库应用程序,并将xml集成到我的android清单文件中。没有编译错误。

第一个屏幕是库应用程序的登录屏幕,当调用它时,它会在以下位置抛出java lang类异常错误:

代码语言:javascript
复制
m_app = (TodoApplication) getApplication();

Loginscreen.java源码:

代码语言:javascript
复制
public class LoginScreen extends Activity {

final static String TAG = LoginScreen.class.getSimpleName();

private TodoApplication m_app;
private Button m_LoginButton;
private BroadcastReceiver m_broadcastReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.login);

    m_app = (TodoApplication) getApplication();

    // supposed to help with the banding on the green background



    findViewById(R.id.loginbackground).getBackground().setDither(true);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.todotxt.todotxttouch.ACTION_LOGIN");
    m_broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Intent i = new Intent(context, TodoTxtTouch.class);
            startActivity(i);
            finish();
        }
    };
    registerReceiver(m_broadcastReceiver, intentFilter);

    m_LoginButton = (Button) findViewById(R.id.login);
    m_LoginButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            login();
        }
    });

    //final RemoteClient remoteClient = m_app.getRemoteClientManager()
        //  .getRemoteClient();
    //if (remoteClient.isAuthenticated()) {



        switchToTodolist();
    //}
}

private void switchToTodolist() {
    Intent intent = new Intent(this, TodoTxtTouch.class);
    startActivity(intent);
    finish();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    unregisterReceiver(m_broadcastReceiver);
}


void login() {
    final RemoteClient client = m_app.getRemoteClientManager()
            .getRemoteClient();

    if (!client.isAvailable()) {
        Log.d(TAG, "Remote service " + client.getClass().getSimpleName()
                + " is not available; aborting login");
        Util.showToastLong(m_app, R.string.toast_login_notconnected);
    } else {
        RemoteLoginTask loginTask = client.getLoginTask();
        loginTask.showLoginDialog(this);
    }
}

}

安卓manifest.xml中的集成库代码:

代码语言:javascript
复制
<activity android:name="com.todotxt.todotxttouch.LoginScreen" android:label="@string/app_label"
        android:theme="@android:style/Theme.NoTitleBar"
        android:configChanges="keyboardHidden|orientation">     
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="com.todotxt.todotxttouch.category.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />            
        </intent-filter>


    </activity>

    <activity android:name="com.todotxt.todotxttouch.TodoApplication" /> 

    <activity android:name="com.todotxt.todotxttouch.Filter" android:label="Filter"
        android:theme="@android:style/Theme.NoTitleBar" />
    <activity android:name="com.todotxt.todotxttouch.Preferences" android:label="@string/set_preferences" />
    <activity android:name="com.todotxt.todotxttouch.AddTask" android:label="@string/addtask"
        android:theme="@android:style/Theme.NoTitleBar"
        android:configChanges="orientation|keyboardHidden"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

    <activity-alias android:name="com.todotxt.todotxttouch.AddTaskShortcut"
        android:targetActivity="com.todotxt.todotxttouch.AddTask" android:label="@string/shortcut_addtask_name">
        <intent-filter>
            <action android:name="android.intent.action.CREATE_SHORTCUT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity-alias>
    <activity-alias android:name="com.todotxt.todotxttouch.AddTaskShare"
        android:targetActivity="com.todotxt.todotxttouch.AddTask" android:label="@string/share_addtask_name">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity-alias>
    <activity android:name="com.todotxt.todotxttouch.HelpActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <activity android:name="com.todotxt.todotxttouch.TodoTxtTouch" android:theme="@android:style/Theme.NoTitleBar"
        android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>

有人能帮我理解这个问题吗?

让我进一步解释一下:我有一个名为Todoapplication.java....so的文件,类exists...it在LoginScreen.java中被调用为

代码语言:javascript
复制
m_app = (TodoApplication) getApplication();

这就是我得到java lang类异常的地方吗?

EN

回答 2

Stack Overflow用户

发布于 2011-12-19 02:41:07

Activity.getApplication()返回在<application>元素的清单中声明的应用程序类的实例。我在你粘贴的清单上看不到。

仅仅在您的应用程序中包含应用程序类是不够的。它必须在清单中显式指定为一个。

票数 0
EN

Stack Overflow用户

发布于 2011-12-19 03:00:50

我可能弄错了,所以我提前请求编程之神的宽恕。

假设您在Eclipse中进行开发,这不是一个简单的例子,在Eclipse中有一个包含开源的项目,在项目属性中有isLibrary选项。

在项目的属性中,您可以添加库,Eclipse将列出开放源码的库(以及选中了"isLibrary“的任何其他库)。您是否可以简单地选择开源项目并添加它。然后,您的项目将添加库并重新构建吗?

要访问开源项目,现在是一个库,您可以使用"import“语句来访问任何公开的公共方法。

使用开源库项目进行设置的一个很好的例子是Actionbar Sherlock,我在youtube上写了一个教程,直观地演示了我刚刚写的内容。它可以在http://www.youtube.com/watch?v=avcp6eD_X2k上找到

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8553829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档