I started the course from coursera and simply created my firsy Android application using the sdk on eclipse but it gave a large amount of errors in the MainActivity.java
file as well as in the other layout files.
Main error it gave was The import android.support.v7.app cannot be resolved
After wards I guess all errors are there because of this main error. On mmethod OnCreate
I got this error The method onCreate(Bundle) of type MainActivity must override or implement a supertype method
No idea of Android
so I hope someone can help me out here.
package com.example.helloandroid;
import android.support.v7.app.ActionBarActivity;//Here I got the error
import android.support.v7.app.ActionBar;//Here as well
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@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();
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 {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
You need to add the support package v7 to your set up.
Check this official tutorial: https://developer.android.com/tools/support-library/setup.html
尝试从sdk \\ extras \\ android \\ support \\ v7导入android.support.v7.app到您的工作区中,然后将此库附加到您的项目中,如果不解决所有错误,则随后将其注释:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.