android-如何使用用户数据进行绘图

android-如何使用用户数据进行绘图,android,achartengine,Android,Achartengine,我有一个根据用户数据进行计算的程序。 该程序运行良好,但当我试图使用achartengine制作绘图时,它崩溃了。(不进行绘图) Intent searchIntent = new Intent(); searchIntent.setClassName("com.mypackage",searrchActivity.class.getName()); searchIntent.putExtra("value", initcores); // ke

我有一个根据用户数据进行计算的程序。 该程序运行良好,但当我试图使用achartengine制作绘图时,它崩溃了。(不进行绘图)

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
我不确定是否在LineGraph类中正确传递了数据

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
据我所知,我必须使用

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
“Bundle sth=getIntent.getExtras()” 但我不知道该把它放在线形图的什么地方

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
我有一个number_cores类,用户在其中输入数据,然后按下计算按钮,在另一个活动中显示结果。 在这方面,我有:

public void cores_func(){
             double initcores=Double.parseDouble(num_cores.getText().toString().trim());
             double half_time=Double.parseDouble(halftimecores.getText().toString().trim());
             double ttime=Double.parseDouble(timecores.getText().toString().trim());
             double l=Math.log(2)/half_time;
             double fcores=initcores*Math.exp(-l*ttime);
             
             
             Intent i=new Intent(this,core_calcs.class);
             i.putExtra("value",fcores);
             i.putExtra("value2",initcores);
             startActivity(i);  
         }
Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
然后,在core_calcs类中(正如您从上面的意图中所看到的),我显示了结果,还添加了一个按钮,当用户单击它时,它会显示图形(现在,它在这里崩溃)

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
我在onCreate方法中有(core_calcs):

double fcores=getIntent().getExtras().getDouble("value");
        double initcores=getIntent().getExtras().getDouble("value2");
Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
然后:

 public void onClick(View v) {
    switch (v.getId()){
    case R.id.show_cores_graph:
        double fcores=getIntent().getExtras().getDouble("value");
        double initcores=getIntent().getExtras().getDouble("value2");
        Intent i = new Intent();        
        i.setClassName("com.wordpress.androiddevgeo.Radiation",LineGraph.class.getName());                 
        i.putExtra("value", fcores);
        i.putExtra("value2", initcores);
        this.startActivity(i);  
        break;
      }      
    }
Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
(另外,我在这里有公共的void LineGraphHandler(视图)

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
最后,在LineGraph类中(如上所述):

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
公共类线形图扩展活动{
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle extras=getIntent().getExtras();
字符串fcores=extras.getString(“值”);
String initcores=extras.getString(“value2”);
}
公共意图getIntent(上下文){
//double ttime=getIntent(context.getExtras().getDouble(“value”);
double[]x={0100};//时间轴
double[]y={initcores,fcores};//轴上的核数
TimeSeries系列=新的TimeSeries(“核心数”);

对于(int i=0;iBundle方法:

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
在“线条图”活动中:

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
class LineGraph extends Activity{
   private Double initcores;
   private Double fcores;

   public Double getInitcores(){ return this.initcores;} 
   public void setInitcores(Double initcores){ this.initcores=initcores;} 
   public Double getFcores(){ return this.fcores;} 
   public void setFcores(Double fcores){ this.fcores=fcores;} 


   public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    ......
    Bundle extras = getIntent().getExtras(); 
    Double initcores= extras.getDouble("value"); 
    setInitcores(initcores); 
    Double fcores= extras.getDouble("value2"));
    setFcores(fcores);

    }
  public Intent getIntent(...){
                  Double initcores= getInitcores();
                  Double fcores= getFcores();
           //yourcode 
  }
}
共享参考方法:

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
    SharedPreferences sp =PreferenceManager.getDefaultSharedPreferences(this);      
    SharedPreferences.Editor ed= sp.edit();
    ed.putInt("screen_width", 480);     
    ed.commit();        
在你的下一个活动中

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    int width = sp.getInt("screen_width",default_int_value);

希望这有助于abit

将其设置为一个捆绑包,或者设置为SharedReferences,或者如果您希望它们是持久的,请使用sqlite。当它崩溃时,请显示您的异常。谢谢这里是您的onCreate(捆绑包…)在LineGraph活动中?我没有!我尝试了Bundle,但没有成功。您能告诉我“Bundle”的确切位置和方式吗?因为我不熟悉SharedReferences,我不理解。我正在更新错误消息:我回答了上面的问题。请检查。谢谢!检查这一行searchIntent.setClassName(“com.mypackage”,searchActivity.class.getName());:我更新了我的“public void onClick(View v)”和LineGraph类。问题是在onCreate methid中我使用了“String fcores=…”但是在“public Intent getIntent(Context Context)”中如何使用这个变量?另外,在onCreate方法中我不使用“setContentView”“方法,因为它假定要进行绘图。还有什么要做的?谢谢!:)您确定需要一个活动类来反映和显示包含组件的UI吗?如果不需要,您可能希望使用一个带有一组方法和字段的常用类。在这种情况下,如果您希望使用getIntent()中的变量方法您应该使用一个全局私有变量,并在onCreate()方法中进行设置:首先感谢您宝贵的帮助!我现在有两个问题:1)我想传递两个字符串,因此如果使用两次getMyString(),它将不起作用。(它说的是“复制方法”)。2)在显示结果和按钮的core_calcs类中“显示图形”存在,我不需要启动活动“线条图”吗?如果不启动活动,我无法理解如何进行。再次感谢!
Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);