2015-03-13 76 views
1

所以在我的Android项目有意图,停止工作,我不知道为什么,其工作之前,我检查,如果只是意图的工作,但它不是,当我试图只是通过单击更改按钮上的文字工作:Eclipse Android - 意图停止工作

试图从这里移动:

public class Level_Of_training extends Activity implements OnClickListener { 

Intent i; 
Button Beginner; 
Button Intermediate; 
Button Advanced; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_level__of_training); 

    Beginner = (Button) findViewById(R.id.Beginner_bt); 
    Intermediate = (Button) findViewById(R.id.Intermediate_bt); 
    Advanced = (Button) findViewById(R.id.Advanced_bt); 

    Beginner.setOnClickListener(this); 
    Intermediate.setOnClickListener(this); 
    Advanced.setOnClickListener(this); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.level__of_training, menu); 
    return true; 
} 

@Override 
public void onClick(View v) { 



    boolean beginner  = v.getId() == this.Beginner.getId(); 
    boolean intermediate = v.getId() == this.Intermediate.getId(); 
    boolean advanced  = v.getId() == this.Advanced.getId(); 

    if (beginner || intermediate || advanced) { 
     if (beginner) { 
      Global.questionare.setTraining_level(Global.TRAINING_LEVEL_BEGINNER); 
     } 
     else if (intermediate) { 
      Global.questionare.setTraining_level(Global.TRAINING_LEVEL_INTERMEDIATE); 
     } 
     else if (advanced) { 
      Global.questionare.setTraining_level(Global.TRAINING_LEVEL_ADVANCED); 
     } 

     SharedPreferences prefs = getSharedPreferences("com.example.shreddedacademy", Context.MODE_PRIVATE); 
     SharedPreferences.Editor editor = prefs.edit(); 

     editor.putInt("type", Global.questionare.getBody_type()); 
     editor.putInt("goal", Global.questionare.getTraining_goal()); 
     editor.putInt("level", Global.questionare.getTraining_level()); 
     editor.putInt("workout",Global.questionare.getWorkout()); 

     editor.commit(); 

     i = new Intent(); 
     i.setClass(Level_Of_training.this, InfoActivity.class); 
     startActivity(i); 
    } 
} 

}

到这里:

public class InfoActivity extends Activity { 
private ListView listView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_info); 

    listView = (ListView) findViewById(R.id.listView1); 

    SharedPreferences prefs = getSharedPreferences("com.example.shreddedacademy", Context.MODE_PRIVATE); 
    int type = prefs.getInt("type",  -1); 
    int fat  = prefs.getInt("fat",  -1); 
    int goal = prefs.getInt("goal",  -1); 
    int level = prefs.getInt("level",  -1); 
    int workout = prefs.getInt("workout", -1); 

    if (type == -1 || fat == -1 || goal == -1 || level == -1 || workout == -1) 
     this.finish(); 

    Workout w = Global.workouts[workout]; 

    WorkoutAdapterItem[] items = new WorkoutAdapterItem[w.Size() + w.get_excercises().size()]; 
    boolean next_is_header = true; 
    int header_count = 0; 
    int current_excercise = 0; 

    for (int i = 0; i < items.length; i++) { 
     if (next_is_header) { 
      items[i] = new WorkoutAdapterItem(String.valueOf(Character.toChars('A' + header_count)), 30); 
      header_count++; 
      current_excercise = 0; 
      next_is_header = false; 
     } else { 
      items[i] = new WorkoutAdapterItem(w.get_excercise(header_count - 1, current_excercise), 20); 
      current_excercise++; 
      if (current_excercise == w.get_excercises().get(header_count - 1).size()) { 
       next_is_header = true; 
      } 
     } 
    } 

    CustomAdapter cadapter = new CustomAdapter(this, R.layout.list_view_item, items); 
    listView.setAdapter(cadapter); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.info, menu); 
    return true; 
} 

}

+0

你现在在哪里定义按钮,你在哪里调用他们的OnClickListener? – TooManyEduardos 2015-03-13 19:50:11

+0

你可以添加清单在线 – n1ckname152 2015-03-14 00:17:24

+0

后Logcat ?? – 2015-03-14 04:46:33

回答

0

试试这个:

i = new Intent(Level_Of_training.this, InfoActivity.class); 
    startActivity(i); 

(上述替换Level_of_training类的底部)

+0

那不起作用 – Daniel 2015-03-13 20:33:53

+0

你能上传Manifest吗? – n1ckname152 2015-03-13 20:42:58

0

你可以试试这个:

Intent in = new Intent(getApplicationContext(), InfoActivity.class); startActivity(in);

+0

这是行不通的 – Daniel 2015-03-13 20:33:37

0

那么它看起来就像你的条件不令人满意,我只能猜测由于描述不够而试图放置断点和鳍d出错的地方。