Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android会话管理不工作_Java_Android_Android Manifest_Session Management_Activitynotfoundexception - Fatal编程技术网

Java Android会话管理不工作

Java Android会话管理不工作,java,android,android-manifest,session-management,activitynotfoundexception,Java,Android,Android Manifest,Session Management,Activitynotfoundexception,我正在尝试用Android管理会话。我使用共享首选项来存储用户数据。当任何用户完全登录并且我的应用程序的主页现在应该打开时,问题就会出现,但Logcat显示错误,即没有活动来处理此页面。 下面是Login.java的代码 public class Login extends Activity { Button but; TextView tex,tex2; EditText nameEdit,passEdit; public static final Strin

我正在尝试用Android管理会话。我使用共享首选项来存储用户数据。当任何用户完全登录并且我的应用程序的主页现在应该打开时,问题就会出现,但Logcat显示错误,即没有活动来处理此页面。
下面是Login.java的代码

public class Login extends Activity {
    Button but;
    TextView tex,tex2;
    EditText nameEdit,passEdit;

    public static final String MyPREFERENCES = "MyPrefs" ;
       public static final String name = "nameKey"; 
       public static final String pass = "passwordKey"; 
       SharedPreferences sharedpreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    but=(Button)findViewById(R.id.login);

 // nameEdit, passEdit get the user entered username and password respectively.
    nameEdit = (EditText)findViewById(R.id.editText1);
    passEdit = (EditText)findViewById(R.id.editText2);

but.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

//storing userdetails in Shared Preference
         Editor editor = sharedpreferences.edit();
              String u = nameEdit.getText().toString();
              String p = passEdit.getText().toString();
              editor.putString(name, u);
              editor.putString(pass, p);
              editor.commit();
             Intent openStartingPoint=new Intent("app.something.com.Menu");
            startActivity(openStartingPoint); //here occurs the error no activity found to handle this
            finish();
            return;

        }
    });
}    
   @Override
   protected void onResume() {

 //if user already logged in then direct him to "Menu".
      sharedpreferences=getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      if (sharedpreferences.contains(name))
      {
      if(sharedpreferences.contains(pass)){
         Intent i = new Intent("app.something.com.Menu");  
         startActivity(i);     
      }
      }
      super.onResume();
   }
}
注销用户的方法如下:清除共享首选项编辑器

   public void logout()
   {
    SharedPreferences sharedpreferences = getSharedPreferences(Login.MyPREFERENCES,Context.MODE_PRIVATE);
    Editor editor = sharedpreferences.edit();
    editor.clear();
    editor.commit();
    moveTaskToBack(true);
    Control_panel.this.finish();                            
    return;
   }
这是舱单代码:

<activity
        android:screenOrientation="portrait"
        android:name="app.something.com.Login"
        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="app.something.com.Menu"
     android:label="@string/app_name" >
        <intent-filter>
            <action android:name="app.something.com.Menu" />

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

我不知道为什么会出现ActivityNotFoundException,即使file Menu.java扩展了Activity类,并且在清单中也提到了它。在这个运行时异常之后,当我再次启动我的应用程序时,我会直接进入对应于Menu.java的活动,这正是应该发生的。但只有当有人试图登录时才会出现异常。
请帮帮我

提前感谢:)

打开/启动另一项活动的意图如下

Intent launchAnotherActivity = new Intent(CurrentActivity.this, 
                                             AnotherActivity.class);
startActivity(launchAnotherActivity);
所以,我不认为你写的是正确的