Привет, ребята, Сегодня я начал изучать приложение для Android. Мой гид - новый Бостон: https://buckysroom.org/videos.php?cat=6&video=16731 Я прошел каждый урок до 10-го числа, потому что: Я делал каждый шаг, но приложение вылетает. Вот код XML:Android Developing App crashes
<Button
android:id="@+id/bAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDisplay"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="Add here" />
<TextView
android:id="@+id/tvDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="The total is: " />
</RelativeLayout>
А вот код JAVA:
package com.example.firstpro;
public class MainActivity extends ActionBarActivity {
int c = 0;
Button add, sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add = (Button) findViewById(R.id.bAdd);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
c+=1;
display.setText("You're total is: " + c);
setContentView(R.layout.activity_main);
}
});
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Я действительно не знаю, что здесь проблема. Предупреждений нет даже. Надеюсь на ответы. Спасибо.
с каким сообщением? – Kon
Пахнет http://stackoverflow.com/questions/23653778/nullpointerexception-accessing-views-in-oncreate – laalto
Эй, Конец, проверьте это: http://prntscr.com/3wt2pl. – iYonatan