java.lang.StackOverflowError是什么?

时间:2017-02-13 19:10:15

标签: java

我和java和andriod的新手所以你们都可以帮助我 我将实时检测EMG信号所以我使用graphview 3.0 jar。 然后我用Sumsung galaxy s4设备运行

非常感谢你

运行错误

    /InstantRun: Instant Run Runtime started. Android package is com.example.vibratorchinji.myapplication2, real application class is null.
    D/AndroidRuntime: Shutting down VM
    I/art: Background sticky concurrent mark sweep GC freed 98127(7MB) AllocSpace objects, 21(5MB) LOS objects, 0% free, 65MB/65MB, paused 1.585ms total 1.279s
    I/art: Background partial concurrent mark sweep GC freed 41805(3MB) AllocSpace objects, 2(3MB) LOS objects, 19% free, 67MB/83MB, paused 1.160ms total 128.758ms
    I/art: Background partial concurrent mark sweep GC freed 35604(2MB) AllocSpace objects, 3(20MB) LOS objects, 18% free, 71MB/87MB, paused 2.678ms total 124.584ms
    I/art: Background partial concurrent mark sweep GC freed 41928(3MB) AllocSpace objects, 1(14MB) LOS objects, 16% free, 78MB/94MB, paused 997us total 115.823ms
    W/art: Suspending all threads took: 43.575ms
    I/art: Background sticky concurrent mark sweep GC freed 56363(4MB) AllocSpace objects, 0(0B) LOS objects, 0% free, 116MB/116MB, paused 44.761ms total 116.510ms
    E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.example.vibratorchinji.myapplication2, PID: 25829
                      java.lang.StackOverflowError: stack size 8MB
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6444)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6445)

    /art: Background partial concurrent mark sweep GC freed 34659(2MB) AllocSpace objects, 15(63MB) LOS objects, 21% free, 58MB/74MB, paused 1.194ms total 158.844ms
    I/art: Background partial concurrent mark sweep GC freed 78303(5MB) AllocSpace objects, 2(6MB) LOS objects, 18% free, 72MB/88MB, paused 2.020ms total 168.745ms
    I/art: Background partial concurrent mark sweep GC freed 57256(4MB) AllocSpace objects, 2(15MB) LOS objects, 18% free, 71MB/87MB, paused 1.048ms total 118.516ms
    I/art: Background partial concurrent mark sweep GC freed 34570(2MB) AllocSpace objects, 1(14MB) LOS objects, 16% free, 78MB/94MB, paused 1.180ms total 119.484ms
    D/Error: ERR: exClass=java.lang.StackOverflowError
    D/Error: ERR: exMsg=stack size 8MB
    D/Error: ERR: file=ViewGroup.java
    D/Error: ERR: class=android.view.ViewGroup
    D/Error: ERR: method=resetResolvedLayoutDirection line=6444
    W/art: Suspending all threads took: 127.512ms
    D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
                 at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6444)
                 at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6445)

    I/art: Background partial concurrent mark sweep GC freed 36(2912B) AllocSpace objects, 1(21MB) LOS objects, 14% free, 94MB/110MB, paused 129.490ms total 314.869ms
    D/Error: ERR: TOTAL BYTES WRITTEN: 20146496
    E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
    E/AndroidRuntime: Error reporting crash
                      android.os.TransactionTooLargeException
                          at android.os.BinderProxy.transactNative(Native Method)
                          at android.os.BinderProxy.transact(Binder.java:496)
                          at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4695)
                          at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:95)
                          at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                          at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
    I/Process: Sending signal. PID: 25829 SIG: 9
    Application terminated.

主要活动

import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.app.Activity;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.example.vibratorchinji.myapplication2.Bluetooth.ConnectedThread;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphView.LegendAlign;
import com.jjoe64.graphview.GraphViewSeries.GraphViewStyle;


public class MainActivity extends Activity implements View.OnClickListener {
    @Override
    public void onBackPressed() {
        if (Bluetooth.connectedThread != null)Bluetooth.connectedThread.write("Q");
        super.onBackPressed();
    }

    Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case Bluetooth.SUCCESS_CONNECT:
                    Bluetooth.connectedThread = new ConnectedThread((BluetoothSocket)msg.obj);
                    Toast.makeText(getApplicationContext(),"Connect!",0).show();
                    String s = "Successfully Connected";
                    Bluetooth.connectedThread.start();
                    break;
                case Bluetooth.MESSAGE_READ:
                    byte[] readbuf = (byte[])msg.obj;
                    String strIncome = new String(readbuf,0,5);
                    if (strIncome.indexOf('s')==0 && strIncome.indexOf('.')==2);{
                    strIncome = strIncome.replace("s","");
                    if (isFloatNumber(strIncome)){
                        Series.appendData(new GraphView.GraphViewData(graph2LastXValue,Double.parseDouble(strIncome)),AutoScrollX);
                        if (graph2LastXValue >= Xview && Lock == true){
                            Series.resetData(new GraphView.GraphViewData[] {});
                            graph2LastXValue = 0;
                        }else graph2LastXValue += 0.1;
                        if (Lock == true)graphView.setViewPort(0,Xview);
                        else graphView.setViewPort(graph2LastXValue-Xview,Xview);
                        //refresh
                        GraphView.removeView(graphView);
                        GraphView.addView(graphView);
                    }

                }
            }
        }
    };
            public boolean isFloatNumber(String num){
                try {
                    Double.parseDouble(num);
                }catch (NumberFormatException nfe){
                    return false;
                }
                return true;
            }
    Button bConnect, bDisconnect, bXminus, bXplus;
    ToggleButton tbLock, tbScroll, tbStream;
    static boolean Lock, AutoScrollX, Stream;
    //graph init
    static LinearLayout GraphView;
    static GraphView graphView;
    static GraphViewSeries Series;
    private static double graph2LastXValue = 0;
    private static int Xview = 10;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);

        LinearLayout background = (LinearLayout)findViewById(R.id.bg);
        background.setBackgroundColor(Color.BLACK);
        init();
        Buttoninit();
    }
    void init(){
        Bluetooth.gethandler(mHandler);
        GraphView = (LinearLayout)findViewById(R.id.Graph);
        Series = new GraphViewSeries("Signal",new GraphViewStyle(Color.YELLOW,2),new GraphViewData[]
                {new GraphViewData(0,0)});
        graphView = new LineGraphView(this, "Graph");
        graphView.setViewPort(0,Xview);
        graphView.setScrollable(true);
        graphView.setScalable(true);
        graphView.setShowLegend(true);
        graphView.setLegendAlign(LegendAlign.BOTTOM);
        graphView.setManualYAxis(true);
        graphView.setManualYAxisBounds(5,0);
        graphView.addSeries(Series);
        graphView.addView(graphView);

    }
    void Buttoninit(){
        bConnect = (Button)findViewById(R.id.bConnect);
        bConnect.setOnClickListener(this);
        bDisconnect = (Button)findViewById(R.id.bDisconnect);
        bDisconnect.setOnClickListener(this);
        bXminus = (Button)findViewById(R.id.bXminus);
        bXminus.setOnClickListener(this);
        bXplus = (Button)findViewById(R.id.bXplus);
        bXplus.setOnClickListener(this);

        tbLock = (ToggleButton)findViewById(R.id.tbLock);
        tbLock.setOnClickListener(this);
        tbScroll = (ToggleButton) findViewById(R.id.tbScroll);
        tbScroll.setOnClickListener(this);
        tbStream = (ToggleButton) findViewById(R.id.tbStream);
        tbStream.setOnClickListener(this);

        Lock = true;
        AutoScrollX = true;
        Stream = false;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bConnect:
            startActivity(new Intent("android.intent.action.BT1"));
            break;
            case R.id.bDisconnect:
            Bluetooth.disconnect();
            break;
            case R.id.bXminus:
            if (Xview>1)Xview --;
            break;
            case R.id.bXplus:
            if (Xview<30)Xview ++;
            break;

            case R.id.tbLock:
            if (tbLock.isChecked()){
                Lock = true;
            }else {
                Lock = false;
            }
                break;
            case R.id.tbScroll:
            if (tbScroll.isChecked()){
                AutoScrollX = true;
            }else {
                AutoScrollX = false;
            }
            break;
            case R.id.tbStream:
            if (tbStream.isChecked()){
                if (Bluetooth.connectedThread != null) Bluetooth.connectedThread.write("E");
            }else {
                if (Bluetooth.connectedThread != null) Bluetooth.connectedThread.write("Q");
            }
            break;
        }
    }
}

Android清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.vibratorchinji.myapplication2">

    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".Bluetooth"
            android:label="Bluetooth">
            <intent-filter>
                <action android:name="android.intent.action.BT1" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

活动主要

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context="com.example.vibratorchinji.myapplication2.MainActivity">

    <LinearLayout
        android:id="@+id/Graph"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_weight="15"/>

    <LinearLayout
        android:id="@+id/LL2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="85">
    <TextView
        android:id="@+id/tvBluetooth"
        android:layout_width="match_parent"
        android:layout_height="18dp"
        android:text="Bluetooth"
        android:textSize="15dp"
        android:textColor="@color/white"/>

        <Button
            android:text="Connect"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bConnect"
            android:textSize="14dp"
            android:textColor="@color/white"/>

        <Button
            android:text="Disconnect"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bDisconnect"
            android:textSize="10dp"
            android:textColor="@color/white"/>

        <TextView
            android:text="Control"
            android:layout_width="match_parent"
            android:layout_height="18dp"
            android:id="@+id/tvControl"

            android:textSize="15dp"
            android:textColor="@color/white"/>

        <ToggleButton
            android:textOff="Start detecting"
            android:textOn="Stop"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:id="@+id/tbStream"

            android:textColor="@color/white"
            android:textSize="11dp"
            android:checked="false"/>

        <ToggleButton
            android:textOff="Auto Scroll X axis"
            android:textOn="Auto Scroll X axis"
            android:layout_width="match_parent"
            android:checked="true"
            android:layout_height="50dp"

            android:id="@+id/tbScroll"
            android:textColor="@color/white"
            android:textSize="9dp"/>

        <ToggleButton
            android:textOff="Lock x axis"
            android:textOn="Lock x axis"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:id="@+id/tbLock"

            android:textColor="@color/white"
            android:checked="true"/>
        <LinearLayout
            android:id="@+id/LLX"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                    android:text = "+"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/bXplus"
                    android:textSize="10dp"
                    android:textColor="@color/white"
                    android:layout_weight="50"/>

            <Button
            android:text = "-"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bXminus"
            android:textSize="10dp"
            android:textColor="@color/white"
            android:layout_weight="50"/>
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

0 个答案:

没有答案