活动将无法启动.....调试此显示以下内容源附件不包含文件Activity.Class的源

时间:2013-09-10 19:17:39

标签: android api

但是android.app.Activity被导入到Class中 这是我的问题

我不得不重新安排代码,以便所有对必要api的调用都会在Dashboard活动中发生(这是我的Launcher和主要活动)为什么我这样做,是因为我需要打开这个网络的连接网站,我可以从这个网站上的不同api检索各种信息(模拟浏览器如何做到这一点)。我发现当我启动并停止应用程序中的活动时,活动关闭时关闭了与Web的连接。因此,每当我尝试获取其他信息时,我都需要登录。我在应用程序中有很多活动。这由仪表板控制(选项卡动作)。上一个代码(工作版本在https://github.com/janbenson/agentpitstop上的GITHUB上),这是当前没有工作的代码

1. Main Activity (dashboard)

                package com.jbsoft.android;
            ...


            public class DashboardActivity extends TabActivity {
                            }
                        // Check login status in database
                           userFunctions = new UserFunctions();

                           String logged_in = userFunctions.isUserLoggedIn( );

                            if (logged_in == "FALSE") {
                             // user is not logged in show login screen
                              Intent login = new Intent(this, LoginActivity.class);
this is line that it hangs up on --------->   startActivity(login);
                              UserFunctions userFunction = new UserFunctions();

2.LoginActivity

                package com.jbsoft.android;
            import java.io.File;
            import java.io.FileNotFoundException;
            import java.io.FileReader;
            import java.io.FileWriter;
            import java.io.IOException;

            import org.json.JSONException;
            import org.json.JSONObject;
            import com.jbsoft.library.UserFunctions;

            import android.app.Activity;
            import android.app.AlertDialog;
            import android.content.DialogInterface;
            import android.os.Bundle;
            import android.os.Environment;
            import android.view.View;
            import android.view.Window;
            import android.widget.Button;
            import android.widget.EditText;
            import android.widget.TextView;
            import android.widget.Toast;

            public class LoginActivity extends Activity {
                Button btnLogin;
              //  Button btnLinkToRegister;
                EditText inputUsername;
                EditText inputPassword;
                TextView loginErrorMsg;
                private static String loginURL = "http://api.agentpitstop.com/mobile/authenticate.php";
                private static String root = Environment.getExternalStorageDirectory().toString();

                // JSON Response node names
                private static String KEY_SUCCESS = "success";
                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    requestWindowFeature(Window.FEATURE_LEFT_ICON);
                    setContentView(R.layout.apslogin);
                    setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.vb1);

                    // Importing all assets like buttons, text fields
                    inputUsername = (EditText) findViewById(R.id.loginUsername);
                    inputPassword = (EditText) findViewById(R.id.loginPassword);
                    btnLogin = (Button) findViewById(R.id.btnLogin);
                  //  btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
                    loginErrorMsg = (TextView) findViewById(R.id.login_error);

                    // Login button Click Event
                    btnLogin.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {

                            String username = (inputUsername.getText().toString()).trim();
                            String password = inputPassword.getText().toString();
                            String temp = username;
                            temp = temp.replaceAll(" ", "%20");
                            username = temp;
                            String parmaction = "?action=login";
                            String parmusername = "&username=";
                            parmusername = parmusername + username;
                            String parmpassword = "&password=";
                            parmpassword = parmpassword + password;
                            String parms = parmaction + parmusername + parmpassword;
                            loginURL = loginURL + parms;

                            GlobalVariable apploginurl = ((GlobalVariable)getApplicationContext());
                            apploginurl.setState(loginURL);
                            finish(); 
                            //UserFunctions userFunction = new UserFunctions();
            /*                JSONObject json = userFunction.loginUser(username, password);

                            // check for login response


                            try {
                                  if (json.getString(KEY_SUCCESS) == "true") {
                                      userFunction.writeToFile(loginURL);
                                      apploginurl.setBaduser(false);
                                      finish();
                            } else{

                                apploginurl.setBaduser(true); 
                                File checkdir = new File (root + "/apsdata") ;
                                userFunction.DeleteRecursive(checkdir);
                                finish();

                                }        
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }*/
                        }
                    });

               /*     btnLinkToRegister.setOnClickListener(new View.OnClickListener() {

                        public void onClick(View view) {
                            Intent i = new Intent(getApplicationContext(),
                                    RegisterActivity.class);
                            startActivity(i);
                            finish();
                        }
                    });*/
                }
                @Override
                protected void onRestart() {
                    // TODO Auto-generated method stub
                    super.onRestart();

                }

            }

最后是我的清单文件

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

                    <activity
                        android:label="@string/app_name"
                        android:name=".DashboardActivity" android:launchMode="standard">
                        <intent-filter >
                            <action android:name="android.intent.action.MAIN" />

                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </activity>

                    <!--  Login Activity -->
                    <activity
                        android:label="Login Account"
                        android:name="com.jbsoft.android.LoginActivity">
                    </activity>
                </application>


            </manifest>

以下是调试运行的logcat .....

            09-10 13:23:22.433: W/dalvikvm(4689): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
            09-10 13:23:22.589: E/AndroidRuntime(4689): FATAL EXCEPTION: main
            09-10 13:23:22.589: E/AndroidRuntime(4689): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jbsoft.android/com.jbsoft.android.DashboardActivity}: java.lang.NullPointerException
            09-10 13:23:22.589: E/AndroidRuntime(4689):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
            09-10 13:23:22.589: E/AndroidRuntime(4689):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
            09-10 13:23:22.589: E/AndroidRuntime(4689):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
            09-10 13:23:22.589: E/AndroidRuntime(4689):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
            09-10 13:23:22.589: E/AndroidRuntime(4689):     at android.os.Handler.dispatchMessage(Handler.java:99)
            09-10 13:23:22.589: E/AndroidRuntime(4689):     at android.os.Looper.loop(Looper.java:123)

1 个答案:

答案 0 :(得分:0)

我实际上做的是回到我正在运行的原始代码并保存全局会话信息,然后检索此代码以识别会话