本文介紹了如何修復Java.lang.StackOverFlow異常?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我不知道在這里該做些什么。我看過Logcat,我知道它位于我的MainActivity類和DrawingTools類之間。我還列出了行號,以幫助識別哪些行是哪些行。我的問題是如何修復此錯誤java.lang.StackOverflow?
這是我的日志:
07-05 00:55:17.852: E/AndroidRuntime(15504): FATAL EXCEPTION: main
07-05 00:55:17.852: E/AndroidRuntime(15504): java.lang.StackOverflowError
07-05 00:55:17.852: E/AndroidRuntime(15504): at java.lang.ref.FinalizerReference.add(FinalizerReference.java:48)
07-05 00:55:17.852: E/AndroidRuntime(15504): at android.os.StrictMode$InstanceTracker.<init>(StrictMode.java:2155)
07-05 00:55:17.852: E/AndroidRuntime(15504): at android.os.StrictMode.trackActivity(StrictMode.java:1857)
07-05 00:55:17.852: E/AndroidRuntime(15504): at android.app.Activity.<init>(Activity.java:768)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:13)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.DrawingTools.<init>(DrawingTools.java:9)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testcad.MainActivity.<init>(MainActivity.java:22)
07-05 00:55:17.852: E/AndroidRuntime(15504): at com.example.testc
這是我的MainActivity類:
13 public class MainActivity extends Activity implements OnClickListener {
14
15 Handler uiHandler;
16 EditText cl;
17 TextView info;
18 Button enter;
19 Button line;
20 Button arc;
21 DrawingUtils callDU = new DrawingUtils();
22 DrawingTools callDT= new DrawingTools();
23 EditTools callET = new EditTools();
24 Conversion callConversion = new Conversion();
25
26 @Override
27 protected void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState);
29 setContentView(R.layout.canvas);
30 31 info = (TextView) findViewById(R.id.info); 32 enter = (Button)findViewById(R.id.enter);
33 line = (Button) findViewById(R.id.line);
34 arc = (Button) findViewById(R.id.arc);
35 cl = (EditText)findViewById(R.id.cl);
36
37 uiHandler = new Handler() { public void handleMessage(Message msg) {
38 switch (msg.what) {
39
40 } Bundle bundle = msg.getData(); String string1 =
41 bundle.getString("P1Key"); String string2 =
42 bundle.getString("P2Key"); info.setText(string1);
43 info.setText(string2); } };
44
45 }
46
47 @Override
48 public void onClick(View v) {
49 switch (v.getId()) {
50 case R.id.enter:
51 String input = cl.getText().toString();
52 synchronized (callDU.string) {
53 String[] In = input.split(",");
54 callDU.setX(In[0]);
55 callDU.setY(In[1]);
56 callDU.setZ(In[2]);
57 callDU.string.notifyAll();
58 }
59
60 break;
61 case R.id.line:
62
63 break;
64 case R.id.arc:
65
66 break;
67 }
68 };
69 }
這是我的DrawingTools類:
7 public class DrawingTools {
8 DrawingUtils callDU = new DrawingUtils();
9 MainActivity callMain = new MainActivity();
10 public class Line extends Thread {
11 Thread line = new Thread();
12 @Override
13 public void run() {
14 // TODO Auto-generated method stub
15 super.run();
16 //Set Text To (Enter Point 1)
17 Message msg = Message.obtain();
18 Bundle bundle = new Bundle();
19 String setTextP1 = "Enter Point 1.";
20 bundle.putString("P1Key", setTextP1);
21 msg.setData(bundle);
22 //callMain.uiHandler.sendMessage(msg);
23 synchronized(callDU.string){
24 try {
25 callDU.string.wait();
26 } catch (InterruptedException e) {
27 // TODO Auto-generated catch block
28 e.printStackTrace();
29 }
30
31 String X1 = callDU.getX();
32 String Y1 = callDU.getY();
33 String Z1 = callDU.getZ();
34 callDU.point.add(X1);
35 callDU.point.add(Y1);
36 callDU.point.add(Z1);
37
38 }
39 Message msg1 = Message.obtain();
40 Bundle bundle1 = new Bundle();
41 String setTextP2 = "Enter Point 2.";
42 bundle1.putString("P2Key", setTextP2);
43 msg1.setData(bundle1);
44 //callMain.uiHandler.sendMessage(msg1);
45 synchronized(callDU.string){
46 try {
47 callDU.string.wait();
48 } catch (InterruptedException e) {
49 // TODO Auto-generated catch block
50 e.printStackTrace();
51 }
52 String X2 = callDU.getX();
53 String Y2 = callDU.getY();
54 String Z2 = callDU.getZ();
55 callDU.point.add(X2);
56 callDU.point.add(Y2);
57 callDU.point.add(Z2);
58 }
59 }
60 }
推薦答案
您對兩個類都有循環引用
DrawingTools類聲明將在init上創建的callMain = new MainActivity();
另一方面,MainActivity類聲明了DrawingTools callDT= new DrawingTools();
,這也將在初始化時提供…
在此方案中,一個類依賴于要構造的另一個類,反之亦然。
這篇關于如何修復Java.lang.StackOverFlow異常?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,