简体   繁体   English

我的Android应用在运行时关闭,代码无错误

[英]My Android app closes on run, no errors in code

I'm coding a dice game as a holiday project, but I'm kinda stuck right now: there are no errors anywhere in my code, but still, the app won't start. 我正在将一个骰子游戏编写为一个度假项目,但是现在我有点卡住:我的代码中没有任何错误,但是该应用程序无法启动。 I really don't see why. 我真的不明白为什么。 I tried cleaning project, fixing properties but nothing works. 我尝试清洁项目,修复属性,但没有任何效果。 Any help would be great. 任何帮助都会很棒。

Java code: Java代码:

package com.bdec.tritsen;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class NamenActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_namen);
}
public void spelregels(View v)
{
    Toast.makeText(getApplicationContext(), "Spelregels komen binnenkort", Toast.LENGTH_SHORT).show();
}

public void beginSpel(View v)
{
    EditText Field1 = (EditText) findViewById(R.id.naam1);
    EditText Field2 = (EditText) findViewById(R.id.naam2);
    EditText Field3 = (EditText) findViewById(R.id.naam3);
    EditText Field4 = (EditText) findViewById(R.id.naam4);
    EditText Field5 = (EditText) findViewById(R.id.naam5);
    EditText Field6 = (EditText) findViewById(R.id.naam6);
    EditText Field7 = (EditText) findViewById(R.id.naam7);
    EditText Field8 = (EditText) findViewById(R.id.naam8);
    EditText Field9 = (EditText) findViewById(R.id.naam9);
    EditText Field10 = (EditText) findViewById(R.id.naam10);

    String naam1 = Field1.getText().toString();
    String naam2 = Field2.getText().toString();
    String naam3 = Field3.getText().toString();
    String naam4 = Field4.getText().toString();
    String naam5 = Field5.getText().toString();
    String naam6 = Field6.getText().toString();
    String naam7 = Field7.getText().toString();
    String naam8 = Field8.getText().toString();
    String naam9 = Field9.getText().toString();
    String naam10 = Field10.getText().toString();


    }
}

The XML code for the buttons: 按钮的XML代码:

<Button
    android:id="@+id/buttonBegin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Begin" 
    android:onClick="beginSpel"/>

<Button
    android:id="@+id/buttonSpelregels"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Spelregels"
    android:onClick="spelregels" />

If it just won't even start and you have no errors in your code or in your logcat then you need to have it declared in your manifest with the Launcher intent-filter . 如果它甚至无法启动,并且您的代码或logcat中没有错误,那么您需要使用Launcher intent-filtermanifest声明它。 Something like 就像是

   <activity
        android:name="com.bdec.tritsen.NamenActivity "
        android:label="NamenActivity " >       
        <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>         
    </activity>

If you already have this then you will need to post logcat so we can see the source of the problem. 如果您已经拥有此功能,则需要发布logcat,以便我们查看问题的根源。

The manifest Docs explain pretty well what can be and what needs to be in the manifest 清单文件说明相当好什么都可以,什么必须在manifest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM