简体   繁体   English

打开跟踪文件时出错:没有这样的文件或目录(2),解决方案?

[英]error opening trace file: No such file or directory (2), Solution?

My app is crashing when i run it, can anybody see what's wrong with it? 运行我的应用程序时崩溃了,有人可以看到它的问题吗? I get this message in the logKat It was running fine until i started messing with UI changing the buttons, TextViews etc.. and changing the enabled and visibility property on them. 我在logKat中收到此消息,直到我开始弄乱UI更改按钮,TextViews等并更改其上的enabled和visible属性后,它运行良好。

12-18 19:08:16.634: E/Trace(636): error opening trace file: No such file or directory (2)

Here is my MainActivity.java 这是我的MainActivity.java

    package com.example.capitales.del.mundo;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;


    public class MainActivity extends Activity {

public int cuenta = 0;

public String[] mPaises = {
        "Canada",
        "Estados Unidos",
        "Mexico",
        "Guatemala",
        "Belice"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button startbutton = (Button) findViewById(R.id.button1);
    Button checkbutton = (Button) findViewById(R.id.button2);
    Button nextbutton = (Button) findViewById(R.id.button3);

    startbutton.setOnClickListener(new View.OnClickListener() {

        Button startbutton = (Button) findViewById(R.id.button1);
        Button checkbutton = (Button) findViewById(R.id.button2);
        Button nextbutton = (Button) findViewById(R.id.button3);
        TextView questionlabel = (TextView) findViewById(R.id.textView1);

        @Override
        public void onClick(View arg0) {

            //start button
    questionlabel.setText(mPaises[cuenta]);
    startbutton.setVisibility(View.GONE);
    checkbutton.setVisibility(0);
    nextbutton.setVisibility(0);
    checkbutton.setEnabled(true);
        }});

    checkbutton.setOnClickListener(new View.OnClickListener() {

        TextView resultadolabel = (TextView) findViewById(R.id.textView2);
        EditText inputbox = (EditText) findViewById(R.id.editText1);
        Button checkbutton = (Button) findViewById(R.id.button2);
        Button nextbutton = (Button) findViewById(R.id.button3);

        @Override
        public void onClick(View v) {
            // check button

            checkbutton.setEnabled(false);
            nextbutton.setEnabled(true);

            if (cuenta == 0) {
                if (inputbox.getText().toString().equals("Ottawa")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Ottawa");}}
            else if (cuenta == 1) {
                if (inputbox.getText().toString().equals("Washington")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Washington");}}
            else if (cuenta == 2) {
                if (inputbox.getText().toString().equals("Mexico")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Mexico");}}
            else if (cuenta == 3) {
                if (inputbox.getText().toString().equals("Guatemala")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Guatemala");}}
            else if (cuenta == 4) {
                if (inputbox.getText().toString().equals("Belmopan")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Belmoopan");}}
        }
    });

    nextbutton.setOnClickListener(new View.OnClickListener() {

        TextView questionlabel = (TextView) findViewById(R.id.textView1);
        TextView resultadolabel = (TextView) findViewById(R.id.textView2);
        EditText inputbox = (EditText) findViewById(R.id.editText1);
        Button checkbutton = (Button) findViewById(R.id.button2);
        Button nextbutton = (Button) findViewById(R.id.button3);

        @Override
        public void onClick(View v) {
            // LO QUE HACE EL NEXT BUTTON
            nextbutton.setEnabled(false);
            checkbutton.setEnabled(true);
            cuenta = cuenta + 1;
            questionlabel.setText(mPaises[cuenta]);
            resultadolabel.setText("");
            inputbox.setText("");



        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

} }

And here is my Activity_Main.xml 这是我的Activity_Main.xml

    <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" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="119dp"
    android:text="@string/Start"
    android:textSize="30sp" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:ems="10"
    android:inputType="text"
    android:visibility="invisible" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/button3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/editText1"
    android:layout_alignParentLeft="true"
    android:enabled="false"
    android:text="@string/next"
    android:textSize="30sp"
    android:visibility="invisible" />

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button3"
    android:layout_alignParentLeft="true"
    android:enabled="false"
    android:text="@string/check"
    android:textSize="30sp"
    android:visibility="invisible" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button2"
    android:layout_alignParentLeft="true"
    android:text="@string/mensaje"
    android:textSize="35sp" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView2"
    android:layout_alignParentLeft="true"
    android:text="@string/pais"
    android:textSize="35sp" />

Try this. 尝试这个。 You don't need to define your buttons and text fields every time. 您无需每次都定义按钮和文本字段。

package com.example.capitales.del.mundo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends Activity {

  public int cuenta = 0;

  public String[] mPaises = {
        "Canada",
        "Estados Unidos",
        "Mexico",
        "Guatemala",
        "Belice"};

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button startbutton = (Button) findViewById(R.id.button1);
    Button checkbutton = (Button) findViewById(R.id.button2);
    Button nextbutton = (Button) findViewById(R.id.button3);
    TextView questionlabel = (TextView) findViewById(R.id.textView1);
    TextView resultadolabel = (TextView) findViewById(R.id.textView2);
    EditText inputbox = (EditText) findViewById(R.id.editText1);

    startbutton.setOnClickListener(new View.OnClickListener() {

    @Override
        public void onClick(View arg0) {

            //start button
    questionlabel.setText(mPaises[cuenta]);
    startbutton.setVisibility(View.GONE);
    checkbutton.setVisibility(0);
    nextbutton.setVisibility(0);
    checkbutton.setEnabled(true);
        }});

    checkbutton.setOnClickListener(new View.OnClickListener() {

    @Override
        public void onClick(View v) {
            // check button

            checkbutton.setEnabled(false);
            nextbutton.setEnabled(true);

            if (cuenta == 0) {
                if (inputbox.getText().toString().equals("Ottawa")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Ottawa");}}
            else if (cuenta == 1) {
                if (inputbox.getText().toString().equals("Washington")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Washington");}}
            else if (cuenta == 2) {
                if (inputbox.getText().toString().equals("Mexico")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Mexico");}}
            else if (cuenta == 3) {
                if (inputbox.getText().toString().equals("Guatemala")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Guatemala");}}
            else if (cuenta == 4) {
                if (inputbox.getText().toString().equals("Belmopan")) {
                    resultadolabel.setText("Correcto");}
                else {resultadolabel.setText("Respuesta correcta: Belmoopan");}}
        }
    });

    nextbutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // LO QUE HACE EL NEXT BUTTON
            nextbutton.setEnabled(false);
            checkbutton.setEnabled(true);
            cuenta = cuenta + 1;
            questionlabel.setText(mPaises[cuenta]);
            resultadolabel.setText("");
            inputbox.setText("");



        }
    });

 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
 }

暂无
暂无

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

相关问题 打开跟踪文件时出错。 没有这样的文件或目录[2] - Error opening trace file. No such file or directory [2] Android - 错误打开跟踪文件:没有这样的文件或目录 - Android - error opening trace file: No such file or directory HttpURLConnection打开跟踪文件时出错:没有这样的文件或目录 - HttpURLConnection Error opening trace file: no such file or directory 打开跟踪文件时出错:没有这样的文件或目录(2)(1)没有这样的表:ContactListTable尝试了数小时找不到解决方案 - Error opening trace file: No such file or directory(2) (1) no such table: ContactListTable Tried for hours can't find solution E / Trace:错误打开跟踪文件:没有这样的文件或目录(2) - E/Trace﹕ error opening trace file: No such file or directory (2) Android E / Trace(627):打开跟踪文件时出错:没有这样的文件或目录(2) - Android E/Trace(627): error opening trace file: No such file or directory (2) Android运行时错误:打开跟踪文件时出错:没有这样的文件或目录(2) - Android runtime error: error opening trace file: No such file or directory (2) LogCat错误打开跟踪文件时出错:没有这样的文件或目录 - LogCat error Error opening trace file: no such file or directory 是什么原因导致打开跟踪文件错误:没有这样的文件或目录? - What cause the error opening trace file: No such file or directory? Android上的JDom:打开跟踪文件时出错:没有这样的文件或目录 - JDom on Android: error opening trace file: No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM