Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 线程以未捕获异常退出(无错误,但强制停止)_Java_Android_Eclipse - Fatal编程技术网

Java 线程以未捕获异常退出(无错误,但强制停止)

Java 线程以未捕获异常退出(无错误,但强制停止),java,android,eclipse,Java,Android,Eclipse,我的JAVA类: package com.example.myprojectname; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget

我的JAVA类:

package com.example.myprojectname;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Data extends Activity implements OnClickListener{

Button start, startFor;
EditText sendET;
TextView gotAnswer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.get);
    initialize();
    }

private void initialize() {

    start = (Button) findViewById(R.id.bSA); 
    startFor = (Button) findViewById(R.id.bSAFR);
    sendET = (EditText) findViewById(R.id.etSend);
    gotAnswer = (TextView) findViewById(R.id.tvGot);

    start.setOnClickListener(this);
    startFor.setOnClickListener(this);
    }

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch (arg0.getId()){
    case R.id.bSA:
        String bread = sendET.getText().toString();
        Bundle basket = new Bundle();
        basket.putString("key", bread);
            Intent a = new Intent (Data.this, OpenedClass.class);
        a.putExtras(basket);
        startActivity(a);
        break;
    case R.id.bSAFR:
        break;
    }
    }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
    Bundle basket = data.getExtras();
    String s = basket.getString("answer");
    gotAnswer.setText(s);
}
}







}
我的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
 >

<EditText
    android:id="@+id/etSend"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
   >


</EditText>

<Button
    android:layout_below="@id/etSend"
    android:layout_alignParentRight="true"
    android:id="@+id/bSA"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="StartActivity" />

<Button
    android:layout_toLeftOf="@id/bSA"
    android:layout_alignTop="@+id/bSA"
    android:id="@+id/bSAFR"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="StartActivityResult" />

<TextView
    android:layout_below="@id/bSAFR"
    android:id="@+id/tvGot"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

</RelativeLayout>``
直接从logcat:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myprojectname/com.example.myprojectname.Data}; have you declared this activity in your AndroidManifest.xml?
您需要在清单中声明您的活动



当天的建议:阅读logcat消息,它们通常信息量很大,会为您节省大量时间。

我猜您忘记在清单中指定此活动了


尝试指定在清单中,将以下内容添加到应用程序标记下的清单:

<activity
        android:name="com.example.simplebrowser.Data"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.DEFAULT" />

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

您忘记将
数据作为
活动添加到清单中。
请转到
AndroidManifest.xml
文件,并在标记内添加以下行:

<activity
        android:name=".Data"
        android:label="activity name" >
    <intent-filter>
        <action android:name="android.intent.action.DEFAULT" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


检查您是否已在清单文件中为活动输入了条目,不客气,先生。请不要忘记将帮助您的答案标记为正确的解决方案;)
<activity
        android:name=".Data"
        android:label="activity name" >
    <intent-filter>
        <action android:name="android.intent.action.DEFAULT" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>