android.app.SuperNotCalledException:活动并未通过调用super.onCreate() [英] android.app.SuperNotCalledException: Activity did not call through to super.onCreate()

查看:2376
本文介绍了android.app.SuperNotCalledException:活动并未通过调用super.onCreate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的的Andr​​oid 媒体播放器code。我不知道我在这个code很想念,当我在符合断点运行 MediaPlayer的熔点为新的MediaPlayer()调试模式。在压缩所有文件文件夹播放。但是,当我运行在正常模式下的应用程序的第一个文件播放,然后我得到这个错误:

  android.app.SuperNotCalledException:活动{com.example.mediaplayer / com.example.mediaplayer.MainActivity}没有通过调用super.onCreate()

code:

 包com.example.mediaplayer;
进口的java.io.File;
进口java.io.FileInputStream中;
进口java.io.FileOutputStream中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.util.zip.ZipEntry中;
进口java.util.zip.ZipFile中;
进口org.apache.commons.io.IOUtils;
进口android.app.Activity;
进口android.media.MediaPlayer;
进口android.os.Bundle;
进口android.os.Environment;
进口android.util.Log;
进口android.widget.Button;公共类MainActivity延伸活动{
    私人MediaPlayer的熔点;
    私有静态最后弦乐MAIN_TAG =ERROR;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
     尝试{
    //最后弦乐file_loc = Environment.getExternalStorageDirectory()的toString()。
    //Log.i(\"location\",file_loc);
         ZipFile中的zip =新的ZipFile(/存储/模拟/ 0 / AjeshDocument / sample.zip);         的for(int i = 1;我7;;我++){         入门的ZipEntry = zip.getEntry(样品/蕾哈娜_+ I +MP3);
         如果(入门!= NULL){
             在的InputStream = zip.getInputStream(输入);
             //见注#3。
             文件TEMPFILE = File.createTempFile(_ AUDIO_,.WAV);
             FileOutputStream中出=新的FileOutputStream(临时文件);
             IOUtils.copy(IN,OUT);             //使用临时文件的东西(如玩)
             文件F =临时文件;
             尝试{
                 如果(f.exists())
                 {
                     Log.i(MAIN_TAG,音频文件中找到!);
                     MediaPlayer的熔点为新的MediaPlayer();
                     FIS的FileInputStream =新的FileInputStream(F);
                     mp.setDataSource(fis.getFD());
                     MP prepare()。
                     //mp.setLooping(false);
                     mp.start();
                     //mp.stop();
                    // mp.release();
                     Log.i(MAIN_TAG,合音完了!);
                 }
               其他
                 {
                     Log.i(MAIN_TAG,文件不存在!);
                 }             }
             赶上(IOException异常E)
             {
                 Log.i(MAIN_TAG,e.toString());
             }
         }
         其他{
             //在zip没有这样的记录
         }
        } //最终
         mp.release();     }
         赶上(例外五){
         //处理您的案件除外...         Log.i(MAIN_TAG,e.toString());     }}@覆盖
保护无效onResume(){
    Log.w(信息,应用程序恢复);    super.onResume();
}@覆盖
保护无效的onStop(){
    Log.w(信息,应用程序已停止);    super.onStop();
}@覆盖
保护无效的onDestroy(){
     Log.w(信息,应用destoryed);    super.onDestroy();
}}


解决方案

您没叫活动的onCreate()方法,即超类之一。呼叫加入 MainActivity 的onCreate()方法:

 公共类MainActivity延伸活动{    私人MediaPlayer的熔点;
    私有静态最后弦乐MAIN_TAG =ERROR;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState); //此行缺少    尝试{
    //你的code ...

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.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();
}

}

解决方案

You didn't call the Activity's onCreate() method, i.e the super class' one. Add the call to MainActivity's onCreate() method:

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

    try {
    // your code...

这篇关于android.app.SuperNotCalledException:活动并未通过调用super.onCreate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆