这是错误显示的位置(list
文件)
LoginActivity.java
我正在尝试调用的登录类位于slideActivity下并扩展Intent intent = new Intent(LoginActivity.this, Login.class);
startActivity(intent); //showing error here
finish();
,而android.support.v4.app.Fragment
是一个单独的包下的单独活动,并扩展为LoginActivity
。
我已将Activity
和slideActivity
添加到Android清单文件中。但错误是因为LoginActivity
类。
错误如下所示:
Login
这是我的android清单文件
12969-12969/com.client.businesstracker E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.client.businesstracker/com.client.businesstracker.Login}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1624)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423)
at android.app.Activity.startActivityForResult(Activity.java:3388)
at android.app.Activity.startActivityForResult(Activity.java:3349)
at android.app.Activity.startActivity(Activity.java:3584)
at android.app.Activity.startActivity(Activity.java:3552)
at com.client.businesstracker.activity.LoginActivity$3.onResponse(LoginActivity.java:150)
at com.client.businesstracker.activity.LoginActivity$3.onResponse(LoginActivity.java:120)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
这是Login.java文件
<activity
android:name=".SlideActivity"
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=".activity.LoginActivity"
android:label="@string/app_name" />
<activity android:name=".activity.RegisterActivity"
android:label="@string/app_name" />
}
这是SlideActivity.java文件,我在这里创建Login文件的对象作为navigationDrawerItem
package com.client.businesstracker;
import com.client.businesstracker.activity.LoginActivity;
import com.client.businesstracker.loginandregistration.helper.SQLiteHandler;
import com.client.businesstracker.loginandregistration.helper.SessionManager;
public class Login extends android.support.v4.app.Fragment {
private TextView txtName;
private TextView txtServerID;
private TextView txtClientID;
private Button btnLogout;
private SQLiteHandler db;
private SessionManager session;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rootview1 = inflater.inflate(R.layout.activity_main, container, false);
txtName = (TextView) rootview1.findViewById(R.id.name);
txtServerID = (TextView) rootview1.findViewById(R.id.server_ID);
txtClientID = (TextView) rootview1.findViewById(R.id.client_ID);
btnLogout = (Button) rootview1.findViewById(R.id.btnLogout);
// SqLite database handler
db = new SQLiteHandler(getActivity());
// session manager
session = new SessionManager(getActivity());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from sqlite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
String serverID = user.get("serverID");
String clientID = user.get("clientID");
// Displaying the user details on the screen
txtName.setText(name);
txtServerID.setText(serverID);
txtClientID.setText(clientID);
// Logout button click event
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoutUser();
}
});
return rootview1;
}
/**
* Logging out the user. Will set isLoggedIn flag to false in shared
* preferences Clears the user data from sqlite users table
* */
private void logoutUser() {
session.setLogin(false);
db.deleteUsers();
// Launching the login activity
Intent intent = new Intent(this.getActivity(), LoginActivity.class);
startActivity(intent);
getActivity().finish();
}
}
这是LoginActivity.java
package com.client.businesstracker;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class SlideActivity extends AppCompatActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
//private ListView mDrawerList;
//private ArrayAdapter<String> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slide);
// mDrawerList = (ListView)findViewById(R.id.left_drawer);
// addDrawerItems();
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
Fragment objFragment = null;
Log.i("MyActivity", "onNavigationDrawerItemSelected() — get item number " + position);
switch (position)
{
case 0:
objFragment = new Login();
break;
case 1:
objFragment = new Connect();
break;
case 2:
objFragment = new Home();
break;
case 3:
objFragment = new Preferences();
break;
case 4:
objFragment = new AboutUs();
break;
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, objFragment)
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 0:
mTitle = getString(R.string.title_section1);
break;
case 1:
mTitle = getString(R.string.title_section2);
break;
case 2:
mTitle = getString(R.string.title_section3);
break;
case 3:
mTitle = getString(R.string.title_section4);
break;
case 4:
mTitle = getString(R.string.title_section5);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.slide, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_slide, container, false);
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((SlideActivity) activity).onSectionAttached(
getArguments().getInt(ARG_SECTION_NUMBER));
}
}
}
答案 0 :(得分:2)
基本上你没有在 Manifest 文件中定义 Login.class 。
您必须在Manifest中添加Login Activity,如下所示:
<activity android:name=".activity.Login"
android:label="@string/app_name" />
希望这会对你有所帮助。
答案 1 :(得分:0)
在考虑任何其他事情之前先检查异常 com.client.businesstracker.Login 不在你的清单中