gpt4 book ai didi

java - "Unfortunately MyApp has stopped"当我按下一个按钮

转载 作者:行者123 更新时间:2023-12-03 17:49:25 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Unfortunately MyApp has stopped. How can I solve this?

(22 个回答)


3年前关闭。




我用我在 github 上找到的代码做了一个问答游戏,因为我是新手,我想学习编程。
所以,当我按下开始按钮游戏崩溃。我在没有其他类(class)的情况下尝试过,但它仍然崩溃。有我的 MainActivity 类、MainActivity xml 和 AndroidManifest。

MainActivity.java

package com.proje.bilgiyarismasi.bilgiyarismasi;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;


public class MainActivity extends AppCompatActivity {
ImageButton baslat,ayarlar;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
baslat = findViewById(R.id.baslatButonu);
ayarlar = findViewById(R.id.ayarlarButonu);
baslat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, SoruAlani.class);
startActivity(intent);
finish();

}

});
ayarlar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,Ayarlar.class);
startActivity(intent);
finish();
}
});

}
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/deepPurple"
tools:context="com.proje.bilgiyarismasi.bilgiyarismasi.MainActivity"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">


<TextView
android:id="@+id/logoIsim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="@string/logoIsim"
android:textColor="@color/orenji"
android:textSize="50sp"
tools:layout_editor_absoluteX="150dp"
tools:layout_editor_absoluteY="28dp" />

<ImageButton
android:id="@+id/baslatButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/logoIsim"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
app:srcCompat="@drawable/menu_1"
android:adjustViewBounds="true"
/>



<ImageView
android:id="@+id/playButton"
android:layout_width="72dp"
android:layout_height="72dp"
app:srcCompat="@drawable/play_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/baslatButonu"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
android:gravity="center"/>


<TextView
android:id="@+id/basla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/baslatButonu"
android:layout_alignEnd="@id/baslatButonu"
android:layout_alignLeft="@id/baslatButonu"
android:layout_alignRight="@id/baslatButonu"
android:layout_alignStart="@id/baslatButonu"
android:layout_alignTop="@id/baslatButonu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:gravity="center"
android:text="@string/baslat"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
/>

<ImageButton
android:id="@+id/ayarlarButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/baslatButonu"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
app:srcCompat="@drawable/menu_1"
android:adjustViewBounds="true"

/>

<TextView
android:id="@+id/ayarlar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/ayarlarButonu"
android:layout_alignEnd="@id/ayarlarButonu"
android:layout_alignLeft="@id/ayarlarButonu"
android:layout_alignRight="@id/ayarlarButonu"
android:layout_alignStart="@id/ayarlarButonu"
android:layout_alignTop="@id/ayarlarButonu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:gravity="center"
android:text="@string/ayarlar"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />

<ImageView
android:id="@+id/ayarla"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignBottom="@id/ayarlarButonu"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
app:srcCompat="@drawable/settings_button"
android:adjustViewBounds="true"
/>

<TextView
android:id="@+id/sosyalMedya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ayarlarButonu"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="@string/sosyalMedya"
android:textAlignment="center"
android:textStyle="bold"
android:gravity="center"/>

<ImageButton
android:id="@+id/facebookLogo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignTop="@id/sosyalMedya"
app:srcCompat="@drawable/facebook_logo"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitCenter"
android:layout_toLeftOf="@id/sosyalMedya"
android:layout_toStartOf="@id/sosyalMedya"
android:layout_marginTop="30dp"


/>

<ImageButton
android:id="@+id/twitterLogo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignTop="@+id/sosyalMedya"
app:srcCompat="@drawable/twitter_logo"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="@null"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"

/>

<ImageButton
android:id="@+id/slackLogo"
android:layout_width="72dp"
android:layout_height="72dp"
app:srcCompat="@drawable/slack_logo"
android:layout_alignTop="@+id/sosyalMedya"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitCenter"
android:layout_toRightOf="@id/sosyalMedya"
android:layout_toEndOf="@id/sosyalMedya"
android:layout_marginTop="30dp"
/>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.proje.bilgiyarismasi.bilgiyarismasi">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<activity android:name=".TekrarOyna" />
<activity android:name=".OyunKazanma" />
<activity android:name=".SoruAlani" />
<activity android:name=".SureBitti">

</activity>
</application>


</manifest>

日志猫
 05-25 12:28:18.414 6393-6393/com.proje.bilgiyarismasi.bilgiyarismasi 
E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.proje.bilgiyarismasi.bilgiyarismasi, PID: 6393

java.lang.RuntimeException: Unable to start activity

ComponentInfo{com.proje.bilgiyarismasi.bilgiyarismasi/com.proje.bilgiyarismasi.bilgiyarismasi.SoruAlani}:
java.lang.RuntimeException: Font asset not found fonts/Bariol_Regular.otf

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)

at android.app.ActivityThread.access$800(ActivityThread.java:151)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:135)

at android.app.ActivityThread.main(ActivityThread.java:5254)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)



at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Caused by: java.lang.RuntimeException: Font asset not found
fonts/Bariol_Regular.otf

at android.graphics.Typeface.createFromAsset(Typeface.java:190)

at com.proje.bilgiyarismasi.bilgiyarismasi.SoruAlani.onCreate(SoruAlani.java:51)

at android.app.Activity.performCreate(Activity.java:5990)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 

at android.app.ActivityThread.access$800(ActivityThread.java:151) 

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 

at android.os.Handler.dispatchMessage(Handler.java:102) 

at android.os.Looper.loop(Looper.java:135) 

at android.app.ActivityThread.main(ActivityThread.java:5254) 

at java.lang.reflect.Method.invoke(Native Method) 

at java.lang.reflect.Method.invoke(Method.java:372) 



com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
05-25 12:28:20.016 4207-6527/com.android.providers.calendar E/SQLiteLog:
(284) automatic index on view_events(_id)
05-25 12:28:26.129 1535-1602/system_process E/InputDispatcher: channel
'2cf4e81e
com.proje.bilgiyarismasi.bilgiyarismasi/com.proje.bilgiyarismasi.bilgiyarismasi.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

谢谢你的帮助。

最佳答案

您没有正确转换图像按钮。

onCreate() 中使用它

    baslat = (ImageButton)findViewById(R.id.baslatButonu);
ayarlar =(ImageButton) findViewById(R.id.ayarlarButonu);

并在 list 中声明此 Activity
<activity android:name=".Ayarlar">

从日志猫
**java.lang.RuntimeException: Font asset not found fonts/Bariol_Regular.otf**

也添加这个字体文件
Bariol_Regular.otf

请检查此链接
How to use custom font in Android Studio

关于java - "Unfortunately MyApp has stopped"当我按下一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50529548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com