有人可以帮我解决这个问题。 (NoSuchMethodError)我真的不明白这个错误。
我在网上发现了类似的问题,但没有一个发布的解决方案似乎有效。有人可以帮助我。 编辑:我已经在Android Studio上工作了。 My screenshot Other
package com.example.android.xxxxxxxxxxy;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends AppCompatActivity {
private ListView mDrawerList;
private DrawerLayout mDrawerLayout;
private ArrayAdapter<String> mAdapter;
private ActionBarDrawerToggle mDrawerToggle;
private String mActivityTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerList = (ListView)findViewById(R.id.navList);mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mActivityTitle = getTitle().toString();
addDrawerItems();
setupDrawer();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
// The firstbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer happy_birthday_to_me = MediaPlayer.create(this, R.raw.happy_birthday_to_me);
Button playsongmeow = (Button) this.findViewById(R.id.play_song_meow);
assert playsongmeow != null;
playsongmeow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
happy_birthday_to_me.start();
}
});
// The secondbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer birthday = MediaPlayer.create(this, R.raw.birthday);
Button playsongmeoww = (Button) this.findViewById(R.id.play_song_meoww);
assert playsongmeoww != null;
playsongmeoww.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
birthday.start();
}
});
// The thirdbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer happy = MediaPlayer.create(this, R.raw.happy);
Button playsongmeowww = (Button) this.findViewById(R.id.play_song_meowww);
assert playsongmeowww != null;
playsongmeowww.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
happy.start();
}
});
// The fourthbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer original = MediaPlayer.create(this, R.raw.original);
Button playsongmeowwww = (Button) this.findViewById(R.id.play_song_meowwww);
assert playsongmeowwww != null;
playsongmeowwww.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
original.start();
}
});
}
private void addDrawerItems() {
String[] osArray = {"Songs", "Photos", "Videos", "About"};
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
switch (position) {
case 0: //Log History
Intent MainActivity = new Intent(MainActivity.this, MainActivity.class);
startActivity(MainActivity);
break;
case 1: //Log History
Intent Photos = new Intent(MainActivity.this, Photos.class);
startActivity(Photos);
break;
case 2: //Log History
Intent Videos = new Intent(MainActivity.this, Videos.class);
startActivity(Videos);
break;
case 3: //Log History
Intent About = new Intent(MainActivity.this, About.class);
startActivity(About);
default:
}
}
});
}
private void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle("List Menu");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item) {
// Inflate your main_menu into the menu.
int id = item.getItemId();
switch (id){
case R.id.about:
Intent About = new Intent(MainActivity.this, About.class);
startActivity(About);
break;
}
switch (id) {
case R.id.rate:
// Open this Uri.
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.exafmpflle.android.happybirthdayyyy&hl=en"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
}
switch (id){
case R.id.privacy:
// Open this Uri.
Uri uri = Uri.parse("https://docs.google.com/document/d/1DEBh3j3LG5WaF9nT9Gl2hpswa3yD-36MfPhVo3S_p08/edit"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
}
// Activate the navigation drawer toggle
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
错误似乎是说你要覆盖的方法之一是不存在的。尝试仔细检查您要覆盖的方法的拼写。
如果这有帮助,请考虑将此帖标记为答案。