Здесь я пытаюсь открыть мероприятие с именем LevelActivity из MainActivity при событии нажатия кнопки, но когда я пытаюсь открыть My LevelActivity, оно выбрасывает меня из приложения.Файлы XML и JAVA приведены ниже.
Мой LevelActivity.java
public class LevelActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
Button btnEasy = (Button) findViewById(R.id.btnEasy);
Button btnHard = (Button) findViewById(R.id.btnHard);
Button btnNormal = (Button) findViewById(R.id.btnNormal);
btnEasy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int seconds = 120;
int Live = 10;
Intent myIntent = new Intent(LevelActivity.this, GameActivity.class);
myIntent.putExtra("varSeconds", seconds);
myIntent.putExtra("varLive", Live);
startActivity(myIntent);
}
});
btnHard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int seconds = 60;
int Lives = 5;
Intent myIntent = new Intent(LevelActivity.this, GameActivity.class);
myIntent.putExtra("varSeconds", seconds);
myIntent.putExtra("varLive", Lives);
startActivity(myIntent);
}
});
btnNormal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int seconds = 60;
int Live = 10;
Intent myIntent = new Intent(LevelActivity.this, GameActivity.class);
myIntent.putExtra("varSeconds", seconds);
myIntent.putExtra("varLive", Live);
startActivity(myIntent);
}
});
}}
Коддля ActivityMain.java
Это моя основная деятельность, в которой я хочу перейти от основной деятельности к уровню, как я говорил ранее
public class MainActivity extends AppCompatActivity {
ImageButton btnMathPlay, btnMathShare, btnMathRate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnMathPlay = (ImageButton) findViewById(R.id.btnMathPlay);
btnMathShare= (ImageButton) findViewById(R.id.btnMathShare);
btnMathRate = (ImageButton) findViewById(R.id.btnMathRate);
btnMathPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*
* Example of Explicit Intent
* When you click Play Button on the screen
* Game Activity will be started
*/
Intent i = new Intent(MainActivity.this,LevelActivity.class);
startActivity(i);
}
});
btnMathShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*
* Example of Implict Intent
* When you click Share Button on the screen
* Android will find the activities that allow to share messages.
*/
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Just Maths - Fun way to learn Maths. http://www.play.google.com");
startActivity(intent);
}
});
btnMathRate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/*
* Simple Toast Message To Display Message For Short Duration
* Link that to your app landing page.
*/
Toast.makeText(MainActivity.this,"You can open your Google Play landing page",Toast.LENGTH_LONG).show();
}
});
}}
Вот мой XML-файл для LevelActivity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/colorAccent"
tools:context=".LevelActivity"
tools:layout_editor_absoluteY="25dp">
<Button
android:id="@+id/btnEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="134dp"
android:text="Easy" />
<Button
android:id="@+id/btnNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnEasy"
android:layout_alignStart="@+id/btnEasy"
android:layout_alignLeft="@+id/btnEasy"
android:layout_marginStart="0dp"
android:layout_marginLeft="@+id/btnEasy"
android:layout_marginTop="35dp"
android:text="Normal" />
<Button
android:id="@+id/btnHard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnNormal"
android:layout_alignStart="@+id/btnEasy"
android:layout_alignLeft="@+id/btnEasy"
android:layout_alignParentBottom="true"
android:layout_marginTop="36dp"
android:layout_marginBottom="220dp"
android:text="Hard" />
</RelativeLayout>
Пожалуйста, помогите мне разрешить эту проблему, а также, если вам нужен какой-либо другой файл, например, журнал регистрации кошек, пожалуйста, укажите !!
Вот что я нашел на консоли отладки Надеюсь, что это поможет
E/AndroidRuntime: FATAL EXCEPTION: main
Process: cheezycode.com.justmaths, PID: 1634
java.lang.RuntimeException: Unable to start activity ComponentInfo{cheezycode.com.justmaths/cheezycode.com.justmaths.LevelActivity}: android.view.InflateException: Binary XML file line #19: Can't convert to dimension: type=0x12
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2487)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2547)
at android.app.ActivityThread.access$1100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5604)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: android.view.InflateException: Binary XML file line #19: Can't convert to dimension: type=0x12
at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at cheezycode.com.justmaths.LevelActivity.onCreate(LevelActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6358)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2440)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2547)
at android.app.ActivityThread.access$1100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5604)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:668)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7086)
at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1241)
at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:1087)
at
android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:84)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:841)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)