Java android.app.SuperNotCalledException:Activity 没有调用 super.onCreate()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23851962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android.app.SuperNotCalledException: Activity did not call through to super.onCreate()
提问by azesh
Here is my Android
Media player code. I don't know what I am missing in this code, when I run with breakpoint at line MediaPlayer mp = new MediaPlayer()
in Debug
mode. All the files in zip
folder is played. But when I run the application in normal mode the first file is played and then I get this error:
这是我的Android
媒体播放器代码。当我MediaPlayer mp = new MediaPlayer()
在Debug
模式行中使用断点运行时,我不知道这段代码中缺少什么。播放文件zip
夹中的所有文件。但是当我在正常模式下运行应用程序时,会播放第一个文件,然后出现此错误:
android.app.SuperNotCalledException: Activity {com.example.mediaplayer/com.example.mediaplayer.MainActivity} did not call through to super.onCreate()
Code:
代码:
package com.example.mediaplayer;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.commons.io.IOUtils;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.Button;
public class MainActivity extends Activity {
private MediaPlayer mp;
private static final String MAIN_TAG ="ERROR";
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
//final String file_loc= Environment.getExternalStorageDirectory().toString();
//Log.i("location",file_loc);
ZipFile zip = new ZipFile("/storage/emulated/0/AjeshDocument/sample.zip");
for(int i=1;i<7;i++){
ZipEntry entry = zip.getEntry("sample/rihanna_"+i+".mp3");
if (entry != null) {
InputStream in = zip.getInputStream(entry);
// see Note #3.
File tempFile = File.createTempFile("_AUDIO_", ".wav");
FileOutputStream out = new FileOutputStream(tempFile);
IOUtils.copy(in, out);
// do something with tempFile (like play it)
File f = tempFile;
try {
if (f.exists())
{
Log.i(MAIN_TAG,"Audio file found!");
MediaPlayer mp = new MediaPlayer();
FileInputStream fis = new FileInputStream(f);
mp.setDataSource(fis.getFD());
mp.prepare();
//mp.setLooping(false);
mp.start();
//mp.stop();
// mp.release();
Log.i(MAIN_TAG,"Pronounciation finished!");
}
else
{
Log.i(MAIN_TAG,"File doesn't exist!!");
}
}
catch (IOException e)
{
Log.i(MAIN_TAG,e.toString());
}
}
else {
// no such entry in the zip
}
} //for end
mp.release();
}
catch (Exception e) {
// handle your exception cases...
Log.i(MAIN_TAG,e.toString());
}
}
@Override
protected void onResume() {
Log.w("Info", "App Resume");
super.onResume();
}
@Override
protected void onStop() {
Log.w("Info", "App stopped");
super.onStop();
}
@Override
protected void onDestroy() {
Log.w("Info", "App destoryed");
super.onDestroy();
}
}
采纳答案by Onik
You didn't call the Activity
's onCreate()
method, i.e the super class' one. Add the call to MainActivity
's onCreate()
method:
您没有调用Activity
'onCreate()
方法,即超类' 方法。添加调用MainActivity
的onCreate()
方法:
public class MainActivity extends Activity {
private MediaPlayer mp;
private static final String MAIN_TAG ="ERROR";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // this line is missing
// your code below ...