Может ли кто-нибудь мне помочь? Когда я запускаю это, он останавливается перед запуском. Я не знаю, что в этом плохого. Может ли кто-нибудь мне помочь? Когда я запускаю это, он останавливается перед запуском. Я не знаю, что в этом плохого.Android-код не работает
MainActivity.java-
package gangster.cookies;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
TextView textView = (TextView) findViewById(R.id.textView);
ImageView imageView = (ImageView) findViewById(R.id.bc);
public void eat(View view) {
textView.setText(R.string.changed_shit);
imageView.setImageResource(R.drawable.after_cookie);
}
public void uneat(View view) {
textView.setText(R.string.changed_again);
imageView.setImageResource(R.drawable.before_cookie);
}
}
Strings.xml-
<resources>
<string name="app_name">Cookies</string>
<string name="changed_shit">I am full bitch</string>
<string name="changed_again">Feed me again Motherfucker</string>
</resources>
activity_main.xml-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BC8F8F"
android:orientation="vertical"
tools:context="gangster.cookies.MainActivity">
<ImageView
android:id="@+id/bc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:scaleType="centerCrop"
android:src="@drawable/before_cookie" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:text="I am Hungry Bitch"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30sp"
android:textColor="#fff"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Eat Cookie"
android:id="@+id/button"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:onClick="eat"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Uneat"
android:id="@+id/button2"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="100dp"
android:onClick="uneat"/>
</LinearLayout>
</LinearLayout>
Какая ошибка вы получаете? –
К сожалению, файлы cookie перестали работать. –
Это сообщение, которое вы получаете. Пожалуйста, добавьте журналы ошибок из logcat –