我创建了一个应用程序,其中登录用户后转到导航抽屉活动,但当我使用其API使用谷歌地图时出现问题。首先,应用程序在我创建它时没有在清单文件中显示任何错误但是当我运行它显示下面提到的一些错误,并显示调试/清单文件(有错误)。
清单文件(运行前):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.anasrasheed.MadProject">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="26" />
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name=".app.AppController"
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".activity.LoginActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.RegisterActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" />
<activity
android:name=".activity.NavigationDrawer"
android:label="@string/title_activity_navigation_drawer"></activity>
<meta-data
android:name="com.google.android.geo..API_KEY"
android:value="AIzaSyBWJo_Hlo6ix1927PsMkZJRIvsIz7hrTsM"/>
</application>
清单文件(运行后)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.anasrasheed.MadProject" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="26" />
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="com.example.anasrasheed.MadProject.app.AppController"
android:allowBackup="true"
android:debuggable="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.anasrasheed.MadProject.activity.LoginActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.anasrasheed.MadProject.activity.RegisterActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" />
<activity
android:name="com.example.anasrasheed.MadProject.activity.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" />
<activity
android:name="com.example.anasrasheed.MadProject.activity.NavigationDrawer"
android:label="@string/title_activity_navigation_drawer" />
<meta-data
android:name="com.google.android.geo..API_KEY"
android:value="AIzaSyBWJo_Hlo6ix1927PsMkZJRIvsIz7hrTsM" />
<meta-data
android:name="android.support.VERSION"
android:value="26.0.0" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Java文件1(主要)
public class MainActivity extends Activity {
private TextView txtName;
private TextView txtEmail;
private Button btnLogout;
private Button btnCnt;
private SQLiteOpenHelper db;
private SessionManager session;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtName = (TextView) findViewById(R.id.name);
txtEmail = (TextView) findViewById(R.id.email);
btnLogout = (Button) findViewById(R.id.btnLogout);
btnCnt = (Button) findViewById(R.id.btnContinue);
// SqLite database handler
db = new SQLiteOpenHelper(getApplicationContext());
// session manager
session = new SessionManager(getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from SQLite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
String email = user.get("email");
txtName.setText(name);
txtEmail.setText(email);
// Logout button click event
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoutUser();
}
});
btnCnt.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Continue();
}
});
}
/**
* 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(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
private void Continue(){
session.setLogin(true);
Intent int2 = new Intent(MainActivity.this,NavigationDrawerFragment.class);
startActivity(int2);
finish();
}
}
Java File 2(导航抽屉)
public class NavigationDrawer extends Activity
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().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
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
assert actionBar != null;
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
/**
* 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";
public PlaceholderFragment() {
}
/**
* 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;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((NavigationDrawer) activity).onSectionAttached(
getArguments().getInt(ARG_SECTION_NUMBER));
}
}
android:versionCode="1" android:versionName="1.0" >
从已在build.gradle文件中定义的清单中删除这两个。