Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无扩展活动的getIntent_Java_Android_Android Intent_Android Activity - Fatal编程技术网

Java 无扩展活动的getIntent

Java 无扩展活动的getIntent,java,android,android-intent,android-activity,Java,Android,Android Intent,Android Activity,我试图将字符串从ActMain传递到SoundClsRslt,但我的SoundClsRslt不扩展活动。我尝试扩展活动,但它将导致我在此处询问的其他问题: 在程序达到“startActivity(i);”之前,一切都正常工作,应用程序崩溃,日志显示“找不到显式活动类{/com.Hugler.CB.SoundClsRslt};您是否在AndroidManifest.xml中声明了此活动?”。你知道怎么了吗 在为intent创建ActMain和为getintent创建SoundClsRslt段的末尾

我试图将字符串从ActMain传递到SoundClsRslt,但我的SoundClsRslt不扩展活动。我尝试扩展活动,但它将导致我在此处询问的其他问题:


在程序达到“startActivity(i);”之前,一切都正常工作,应用程序崩溃,日志显示“找不到显式活动类{/com.Hugler.CB.SoundClsRslt};您是否在AndroidManifest.xml中声明了此活动?”。你知道怎么了吗


在为intent创建ActMain和为getintent创建SoundClsRslt段的末尾

我的主要代码:

package com.Hugler;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.Audio.CAudio;
import com.Hugler.ADK.ADK;
import com.Hugler.CB.SoundClsRslt;
import com.Hugler.Lib.Cfg;
import com.Hugler.Lib.MyDebug;
import com.Hugler.Network.Server;
import com.Hugler.Network.StreamingServer;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.telephony.SmsManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.Hugler.Personality.Personality;
import com.Hugler.Personality.Miti.PerMiti;
import com.Hugler.TeleOp.TeleOp;
import com.Motor.Motor;
import com.TTS.PCMPlayback;

public class ActMain extends Activity implements ADK.IADK {
    private TextView m_pTxtRslt;
    private TextView m_pTxtRslt1;

    private TextView m_pTxtview;
    private TextView m_pTxtview1;

    public static Button m_pBtnHeadToggle;
    public static Button m_pBtnEarToggle;

    private SoundClsRslt m_pSoundClsRslt;
    private static ActMain _p;

    public static int level;

    final Intent i = new Intent(this, SoundClsRslt.class);
    final Context context = this;
    private TextView result;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        _p = this;

        if (Cfg.Init()) {
            setContentView(R.layout.main);

            // get prompts.xml view
            LayoutInflater li = LayoutInflater.from(context);
            View promptsView = li.inflate(R.layout.prompts, null);

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);

            final EditText userInput = (EditText) promptsView
                    .findViewById(R.id.editTextDialogUserInput);

            // set dialog message
            alertDialogBuilder
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    // get user input and set it to result
                                    // edit text
                                    result.setText(userInput.getText());
                                }

                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();

            result = (TextView) findViewById(R.id.editTextResult);
            result.setText(null);

            m_pTxtRslt = (TextView) findViewById(R.id.TxtRslt);
            m_pTxtRslt1 = (TextView) findViewById(R.id.TxtRslt1);

            m_pTxtview = (TextView) findViewById(R.id.textView2);
            m_pTxtview1 = (TextView) findViewById(R.id.textView3);

            MyDebug.Init(this, m_pTxtRslt);

            m_pTxtRslt.setText("Non-Glass");
            m_pTxtRslt1.setText(null);

            m_pTxtview.setText("Glass");
            m_pTxtview1.setText(null);

            m_pSoundClsRslt = new SoundClsRslt(this);
            SimpleDateFormat pSDF = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
            String sNow = pSDF.format(new Date());
            m_pSoundClsRslt.StartLog(Cfg.GetLogDir() + "/" + sNow + ".csv");

            PCMPlayback.Init();
            Personality.Init(new PerMiti());
            TeleOp.Init(m_pSoundClsRslt);

            if (result != null){
                String easyPuzzle  = result.getText().toString();
                i.putExtra("numberfrom", easyPuzzle);
                startActivity(i);
                Toast.makeText(this, "msg msg", Toast.LENGTH_SHORT).show();
            } //passing string

        } else {
            AlertDialog.Builder pDlg = new AlertDialog.Builder(this);
            pDlg.setTitle("Fail loading configuration");
            pDlg.setMessage(Cfg.ErrMsg());
            pDlg.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ActMain.this.finish();
                }
            });
            pDlg.show();
        }
    }

    protected void onResume() {
        super.onResume();
        if (Cfg.ErrMsg() != null)
            return;

        Server.Init();
            CAudio.Init(m_pSoundClsRslt);
            CAudio.ResumeSoundCls();

        View decorView = getWindow().getDecorView();

        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        decorView.setSystemUiVisibility(uiOptions);
    }

    public void Show0(final String sTxt) {
        runOnUiThread(new Runnable() {
            public void run() {
                m_pTxtRslt.setText(sTxt);
            }
        });
    }

    public void Show1(final String sTxt) {

        runOnUiThread(new Runnable() {
            public void run() {
                m_pTxtRslt1.setText(sTxt);
            }
        });
    }

    public void Show2(final String sTxt) {
        runOnUiThread(new Runnable() {
            public void run() {
                m_pTxtview.setText(sTxt);
            }
        });
    }

    public void Show3(final String sTxt) {
        runOnUiThread(new Runnable() {
            public void run() {
                m_pTxtview1.setText(sTxt);
            }
        });
    }

    public void OnADKStat(int iStat, String sMsg) {

        if (iStat == ADK.S_CONNECTED)
            Motor.Connect(ADK.GetInStream(), ADK.GetOutStream());
        else if (iStat == ADK.S_DISCONNECTED)
            runOnUiThread(new Runnable() {
                public void run() {
                    Motor.Disconnect();
                    ActMain.this.finish();
                }
            });
    }
}
My SoundClsRslt代码:

package com.Hugler.CB;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.Hugler.ActMain;
import com.Hugler.TeleOp.TeleOp;
import com.SoundClassification.SoundClassification.ISC;

import android.app.Activity;
import android.content.Intent;
import android.os.Environment;
import android.telephony.SmsManager;

public class SoundClsRslt implements ISC {

    public static int interact;

    private ActMain m_pMain;
    private static int m_iID;
    private static int m_iID1;
    private FileOutputStream _fLog;

    public SoundClsRslt(ActMain pMain) {
        m_pMain = pMain;
        m_iID = 0;
        m_iID1 = 0;
        _fLog = null;
    }

    public void StartLog(String sFile) {
        if (_fLog != null)
            return;
        try {
            _fLog = new FileOutputStream(sFile);
            String sHdr = "Time,Event,Confidence\n";
            _fLog.write(sHdr.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void OnLog(String sLog) {
    }

    public void OnLog2(String sLog) {
    }

    public void OnSegment(double[] pBuf, int iLen, String sCls, double dConf) {
        sCls = sCls.toLowerCase(Locale.getDefault());
        {
            if (sCls.contains("glass")) {

                m_iID1++;
                m_pMain.Show2(m_iID1 + "." + sCls);
                m_pMain.Show3("" + dConf);

                //convert short to byte
                ByteBuffer myByteBuffer = ByteBuffer.allocate(iLen * 2);
                myByteBuffer.order(ByteOrder.LITTLE_ENDIAN);

                //open pcm
                ShortBuffer myShortBuffer = myByteBuffer.asShortBuffer();
                for (int i = 0; i < iLen ; i++) {
                    myShortBuffer.put((short)(pBuf[i]));
                }
                File file;

                FileChannel out = null;

                try {
                    String filepath = Environment.getExternalStorageDirectory().getPath();
                    SimpleDateFormat pSDF = new SimpleDateFormat("yyyyMMdd_HH_mm_ss", Locale.UK);
                    String sNow = pSDF.format(new Date());
                    file = new File(filepath,"AudioRecorder" + "/segment_" + sNow + ".pcm");

                    Intent intent = getIntent();

                    SimpleDateFormat smsdate = new SimpleDateFormat("yyyy/MM/dd_HH:mm:ss", Locale.US);
                    String messageToSend = "Glass breaking sound detected at "+ smsdate.format(new Date()) + " (yyyy/MM/dd_HH:mm:ss)";
                    String number = intent.getExtras().getString("numberfrom");
                    SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null, null);

                    // if file doesnt exists, then create it
                    if (!file.exists()) {
                        file.createNewFile();
                    }
                    out = new FileOutputStream(file).getChannel();

                    //write to pcm
                    out.write(myByteBuffer);
                    //close pcm
                    out.close();
                } catch (IOException e) {
            e.printStackTrace();
                } finally {
                    try {
                        if (out != null) {
                            out.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

            } else {
            m_iID++;
            m_pMain.Show0(m_iID + "." + sCls);
                m_pMain.Show1("" + dConf);
            }
        }
        TeleOp.SendInteraction();

        if (_fLog != null) {
            SimpleDateFormat pSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
            String sNow = pSDF.format(new Date());
            String sLog = sNow + "," + sCls + "," + dConf + "\n";
            try {
                _fLog.write(sLog.getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
package com.Hugler.CB;
导入java.io.File;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.nio.ByteBuffer;
导入java.nio.ByteOrder;
导入java.nio.ShortBuffer;
导入java.nio.channels.FileChannel;
导入java.text.simpleDataFormat;
导入java.util.Date;
导入java.util.Locale;
import com.Hugler.ActMain;
导入com.Hugler.TeleOp.TeleOp;
导入com.SoundClassification.SoundClassification.ISC;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Environment;
导入android.telephony.smsmsmanager;
公共类SoundClsRslt实现ISC{
公共静态信息交互;
私人律师事务所;
专用静态int m_iID;
专用静态int m_iID1;
私有文件输出流\u fLog;
公共声音CLSRSLT(ActMain pMain){
m_pMain=pMain;
m_iID=0;
m_iID1=0;
_fLog=null;
}
公共文件(字符串文件){
如果(_fLog!=null)
返回;
试一试{
_fLog=新文件输出流(sFile);
字符串sHdr=“时间、事件、置信度\n”;
_fLog.write(sHdr.getBytes());
}捕获(例外e){
e、 printStackTrace();
}
}
public void OnLog(字符串sLog){
}
public void OnLog2(字符串插入){
}
段上的公共void(双[]pBuf,整数iLen,字符串SCL,双dConf){
sCls=sCls.toLowerCase(Locale.getDefault());
{
如果(SCL.包含(“玻璃”)){
m_iID1++;
m_pMain.Show2(m_iID1+“+SCL);
m_pMain.Show3(“+dConf”);
//将短字符转换为字节
ByteBuffer myByteBuffer=ByteBuffer.allocate(iLen*2);
myByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
//开放式pcm
ShortBuffer myShortBuffer=myByteBuffer.asShortBuffer();
对于(int i=0;i
您可以在类的构造函数中定义上下文。聊天后,您可以使用
myContext.getIntent()
获取意图。您的构造函数应该如下所示:

private Context myContext
public SoundClsRslt(ActMain pMain, Context context) {
    m_pMain = pMain;
    m_iID = 0;
    m_iID1 = 0;
    this.myContext = context;
    _fLog = null;
}

您已经将ActMain实例传递给SoundClsRslt。因此,请在SoundClsRslt中放入mpmain.getIntent()而不是getIntent(),然后再试一次。

您能解释一下您试图传递给SoundClsRslt类的字符串是哪一个字符串吗?在创建ActMain for intent,以及在为getintent.ad创建SoundClsRslt段后,将其放入SharedReferences。你的manifast.xml和logcat也会在你的Menifest中声明com.Hugler.CB.SoundClsRslt活动。在程序达到“startActivity(i);”之前,一切正常,应用程序崩溃,logcat说“找不到显式活动类{/com.Hugler.CB.SoundClsRslt};您是否在AndroidManifest.xml中声明了此活动?”。您知道哪里出了问题吗?在程序达到“startActivity(i)”之前,一切都正常工作;,应用程序崩溃,logcat说“找不到显式活动类{/com.Hugler.CB.SoundClsRslt};有