2017-03-22 42 views
0

如果我在onCreate方法之外添加GraphViewer Java代碼,我會收到消息:Cannot resolve symbol addSeries。但是當我將代碼放在onCreate方法中時,應用程序在啓動屏幕後崩潰。請幫忙(代碼之間突出**):如果我在onCreate方法中添加GraphViewer代碼,應用程序崩潰

package yourhome; 

import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.Button; 
import android.widget.TextView; 


import com.jjoe64.graphview.GraphView; 
import com.jjoe64.graphview.series.DataPoint; 
import com.jjoe64.graphview.series.LineGraphSeries; 


import smssca.stefandraegersoftware.de.simplemysqlconnectionapp.datasource.ActivityDataSource; 

public class Hauptfenster extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     **GraphView graph = (GraphView) findViewById(R.id.graph); 
     LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] { 
       new DataPoint(0, 1), 
       new DataPoint(1, 5), 
       new DataPoint(2, 3) 
     }); 
     graph.addSeries(series);** 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_hauptfenster); 

     final TextView textView = (TextView) findViewById(R.id.textView); 

     Button lesenBtn = (Button) findViewById(R.id.lesenBtn); 
     lesenBtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       new ActivityDataSource(textView).execute("someParams"); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.menu_hauptfenster, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { return true;} 
     return super.onOptionsItemSelected(item); 
    } 
} 
+0

秀崩潰 – snachmsm

+0

的堆棧跟蹤設置什麼是崩潰,你的啓動畫面後得到的,是一樣的'無法解析符號addSeries'消息? –

回答

1

移動

GraphView graph = (GraphView) findViewById(R.id.graph); 
    LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] { 
      new DataPoint(0, 1), 
      new DataPoint(1, 5), 
      new DataPoint(2, 3) 
    }); 
graph.addSeries(series); 

下面

super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_hauptfenster); 

這兩條線應該先調用內部onCreate方法在大多數情況下

目前您正在嘗試findViewById(R.id.graph);此刻,當th ERE沒有View s的所有 - 這些在下面setContentView

+0

謝謝你我會試試這個! –

相關問題