2011-12-18 17 views
0

私はAndroidアプリにオープンソースアプリを統合しようとしています。私はライブラリアプリケーションとしてオープンソースのアプリを作って、XMLをAndroidのマニフェストファイルに統合しました。コンパイルエラーはありません。アンドロイド統合ライブラリアプリ

最初の画面では、ライブラリアプリケーションのログイン画面で、それが呼び出されたとき、それは時にJavaのlangクラス例外エラーがスローされます。loginscreen.javaの

m_app = (TodoApplication) getApplication(); 

ソースコード:

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

} 

android manifest.xmlの統合されたライブラリコード:

<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> 

誰もが問題を理解する上で私を助けてもらえます。それは

m_app = (TodoApplication) getApplication(); 

としてLoginScreen.javaから呼び出されている...私はTodoapplication.javaと呼ばれるファイルを持っています....クラスが存在するので、それは私がどこである:

私はさらに説明しましょうJavaのlangクラスの例外を取得していますか?

答えて

0

Activity.getApplication()は、<application>要素のマニフェストで宣言されたアプリケーションクラスのインスタンスを返します。私はあなたのペーストされたマニフェストでそれを見ません。

には、アプリケーション内のアプリケーションクラスがあります。マニフェストの中で明示的に指定する必要があります。

0

私は多分スティックの間違った終わりを得ているので、私はプログラミングの神々に前もって赦しを請う。

Eclipseで開発していると仮定すると、オープンソースソースを持つEclipseでプロジェクトを作成する単純なケースではありません。プロジェクトプロパティ内でisLibraryオプションを選択しています。

あなたのプロジェクトのプロパティでは、ライブラリを追加することができ、Eclipseはオープンソースのもの(および "isLibrary"がチェックされているもの)を一覧表示します。単にオープンソースプロジェクトを選択して追加しないでください。プロジェクトがライブラリを追加してビルドを再開しますか?

オープンソースプロジェクトにアクセスするには、ライブラリを使用して、 "import"ステートメントを使用して公開されているパブリックメソッドにアクセスできます。

オープンソースライブラリプロジェクトを使用したこのセットアッププロセスの良い例は、私が書いたことを視覚的に示すチュートリアルのYouTubeを書いたActionbar Sherlockです。これは、http://www.youtube.com/watch?v=avcp6eD_X2k

で見つけることができます
関連する問題