-1

我的 android 应用程序有问题。我想将 android 应用程序连接到在 jboss 7.1 上运行的 web 服务。当我创建异步任务以在我的 webservicde 上运行方法时,我在 logcat 中收到以下错误:

06-15 15:45:21.731: E/Trace(1958): error opening trace file: No such file or directory (2)
06-15 15:45:45.531: E/AndroidRuntime(1958): FATAL EXCEPTION: AsyncTask #1
06-15 15:45:45.531: E/AndroidRuntime(1958): java.lang.RuntimeException: An error occured while executing doInBackground()
06-15 15:45:45.531: E/AndroidRuntime(1958):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.lang.Thread.run(Thread.java:856)
06-15 15:45:45.531: E/AndroidRuntime(1958): Caused by: java.lang.NullPointerException
06-15 15:45:45.531: E/AndroidRuntime(1958):     at   de.wifhm.se1.android.banking.OnlineBankingSystemStub.login(OnlineBankingSystemStub.java:52)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at de.wifhm.se1.android.LoginActivity$LoginLogoutTask.doInBackground(LoginActivity.java:118)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at de.wifhm.se1.android.LoginActivity$LoginLogoutTask.doInBackground(LoginActivity.java:1)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-15 15:45:45.531: E/AndroidRuntime(1958):     ... 3 more

android 清单如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.wifhm.se1.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:name=".OnlineBankingApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".TransactionsActivity" android:label="@string/labelTransactions"></activity>
        <activity android:name=".PrefsActivity" android:label="@string/labelPrefs"></activity>

    </application>
</manifest>

这是我的 doInBackground 方法:

类 LoginLogoutTask 扩展 AsyncTask {

/**
 * Diese Methode wird in einem nebenläufigen Thread ausgeführt (asynchron). Darum dürfen hier
 * keine View-Elemente zugegriffen werden!
 */
@Override
protected String doInBackground(String... params) {
    StringBuffer output = null;
    if (LoginActivity.this.obsApp.getAngemeldeterKunde() == null) {         
        /* Login durchfuehren */
        String username = LoginActivity.this.prefs.getString("username", "");
        String password = LoginActivity.this.prefs.getString("password", "");
        Kunde angemeldeterKunde = LoginActivity.this.obsApp.getObsStub().login(username, password);
        LoginActivity.this.obsApp.setAngemeldeterKunde(angemeldeterKunde);

        //Ergebnisausgabe:
        output = new StringBuffer("Sie sind eingeloggt als " + angemeldeterKunde.getUserName() + ".\n\nIhre Konten:\n");

        Set<Konto> konten = LoginActivity.this.obsApp.getObsStub().getEigeneKonten();
        for (Konto konto : konten){
            output.append("- Konto " + konto.getKontoNr() + "\n");
            output.append("---Kontostand aktuell: " + LoginActivity.this.obsApp.getObsStub().getKontostand(konto.getKontoNr()) + "EUR\n");
        }
    }
    else {
        /* Logout durchfuehren */
        LoginActivity.this.obsApp.getObsStub().logout();
        LoginActivity.this.obsApp.setAngemeldeterKunde(null);
        output = new StringBuffer("Bitte erneut einloggen.");
    }
    return output.toString();
}

有人能帮我吗?

4

2 回答 2

0

堆栈跟踪指向您的代码在调用您的方法login内部时失败。doInBackground堆栈跟踪中的以下行显示了这一点:

06-15 15:45:45.531: E/AndroidRuntime(1958):     at   de.wifhm.se1.android.banking.OnlineBankingSystemStub.login(OnlineBankingSystemStub.java:52)
06-15 15:45:45.531: E/AndroidRuntime(1958):     at de.wifhm.se1.android.LoginActivity$LoginLogoutTask.doInBackground(LoginActivity.java:118)

考虑到这一点,您的代码会调用一次login,结果是NullPointerException

    String username = LoginActivity.this.prefs.getString("username", "");
    String password = LoginActivity.this.prefs.getString("password", "");
    Kunde angemeldeterKunde = LoginActivity.this.obsApp.getObsStub().login(username, password);

很可能您的代码中有问题,username或者password设置为空。可能两者兼而有之。

您将需要调查其余代码以确定为什么其中一项或两项从prefs.

于 2013-06-15T17:03:39.250 回答
-1

安迪现在很忙。这是 prefs.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <EditTextPreference android:key="username" 
        android:summary="@string/summaryUsername" 
        android:title="@string/titleUsername"/>
    <EditTextPreference android:key="password" 
        android:summary="@string/summaryPassword" 
        android:title="@string/titlePassword" 
        android:password="true"/>
</PreferenceScreen>

和strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="myTitle">Willkommen zum OnlineBanking</string>
    <string name="app_name">OnlineBankingApp</string>
    <string name="titleUsername">Benutzername</string>
    <string name="summaryUsername">Joe</string>
    <string name="titlePassword">Kennwort</string>
    <string name="summaryPassword">Joe1</string>
    <string name="labelPrefs">Einstellungen</string>
    <string name="labelTransactions">Transaktionen</string>
    <string name="bnLogin">Login</string>
    <string name="bnLogout">Logout</string>    
    <string name="bnTransactions">Transaktionen</string>    
    <string name="msgLoginFehlt">Bitte loggen Sie sich ein.</string>

</resources>
于 2013-06-15T17:23:22.237 回答