简体   繁体   English

错误:不幸的是我的拳头应用程序已停止工作

[英]Error : Unfortunately My Fist App has stopped working

I am trying to develop a chat room for an Android App. 我正在尝试为Android应用程序开发聊天室。

On the first screen, a list view is displayed. 在第一个屏幕上,显示list view On clicking on one of the items in listview , an activity is launched in whichh I am displaying two buttons called as Chat and Draw . 单击listview中的一个项目时,将启动一个活动,其中我显示两个称为ChatDraw按钮。 When I click on chat I am launching another activy called as DisplayMessageActiviy in which there is an area for EditText and a button called as Send . 当我点击聊天时,我正在启动另一个名为DisplayMessageActiviy ,其中有一个EditText区域和一个名为Send的按钮。

However, when I click on Chat , I am getting the following error :: Unfortunately My Fist App has stopped working . 但是,当我点击Chat ,我收到以下错误:: Unfortunately My Fist App has stopped working

I am using the following lines of code : 我使用以下代码行:

SingleListActivity.java : SingleListActivity.java

//chatMessage is the xfunction to be run on clicking on chat button
public void chatMessage(View view) 
{
    Intent intent_chat = new Intent(this, DisplayMessageActivity.class);
    //EditText editText = (EditText) findViewById(R.id.edit_message);
    //String message = editText.getText().toString();
    //intent_chat.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent_chat);
}

DisplayMessageActivity.java : DisplayMessageActivity.java

public class DisplayMessageActivity extends Activity {

@SuppressLint("NewApi")

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

}

public void displayChat(View view) 
{
    onResume();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    TextView text = (TextView) findViewById(R.id.chatWindow);
    EditText editBox = (EditText)findViewById(R.id.chatBox);

    String str = text.getText().toString(); 
    text.setText(str +"\n"+editBox.getText().toString());
    editBox.setText("");       

    editBox.setHint("Type in here");

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

} }

I am getting the following error in LogCat : 我在LogCat中收到以下错误:

01-30 10:37:40.055: E/AndroidRuntime(724): FATAL EXCEPTION: main
01-30 10:37:40.055: E/AndroidRuntime(724): java.lang.IllegalStateException: Could not execute method of the activity
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.view.View$1.onClick(View.java:3597)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.view.View.performClick(View.java:4202)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.view.View$PerformClick.run(View.java:17340)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.os.Handler.handleCallback(Handler.java:725)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.os.Looper.loop(Looper.java:137)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 10:37:40.055: E/AndroidRuntime(724):  at java.lang.reflect.Method.invokeNative(Native Method)
01-30 10:37:40.055: E/AndroidRuntime(724):  at java.lang.reflect.Method.invoke(Method.java:511)
01-30 10:37:40.055: E/AndroidRuntime(724):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 10:37:40.055: E/AndroidRuntime(724):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 10:37:40.055: E/AndroidRuntime(724):  at dalvik.system.NativeStart.main(Native Method)
01-30 10:37:40.055: E/AndroidRuntime(724): Caused by: java.lang.reflect.InvocationTargetException
01-30 10:37:40.055: E/AndroidRuntime(724):  at java.lang.reflect.Method.invokeNative(Native Method)
01-30 10:37:40.055: E/AndroidRuntime(724):  at java.lang.reflect.Method.invoke(Method.java:511)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.view.View$1.onClick(View.java:3592)
01-30 10:37:40.055: E/AndroidRuntime(724):  ... 11 more
01-30 10:37:40.055: E/AndroidRuntime(724): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myfirstapp/com.example.myfirstapp.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml?
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-30 10:37:40.055: E/AndroidRuntime(724):  at   android.app.Activity.startActivityForResult(Activity.java:3370)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.app.Activity.startActivityForResult(Activity.java:3331)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.app.Activity.startActivity(Activity.java:3566)
01-30 10:37:40.055: E/AndroidRuntime(724):  at android.app.Activity.startActivity(Activity.java:3534)
01-30 10:37:40.055: E/AndroidRuntime(724):  at com.example.myfirstapp.SingleListActivity.chatMessage(SingleListActivity.java:42)
01-30 10:37:40.055: E/AndroidRuntime(724):  ... 14 more

AndroidManifet.xml :: AndroidManifet.xml ::

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".SingleListItem"
        android:label="@string/title_activity_single_list_item" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".SingleListActivity"
        android:label="@string/title_activity_single_list" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity
        android:name="com.example.appfirst.DisplayMessageActivity"
        android:label="@string/title_activity_display_message"
        android:parentActivityName="com.example.myfirstapp.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.myfirstapp.MainActivity" />
    </activity>
</application>

Can someone help me to sort out the error ??Thanks and Regards. 有人可以帮我解决错误吗?谢谢和问候。

You have to post full stack-trace (logcat errors) and full code with your question 您必须发布完整的堆栈跟踪(logcat错误)和完整的代码与您的问题

anyway just assumption I think problem is here (Assumption - More details needed) 无论如何只是假设我认为问题在这里(假设 - 需要更多细节)

public void displayChat(View view) 
{
    onResume();
}

You can never explicitly call onResume() in Android Activity.. 你永远不能在Android Activity中显式调用onResume() ..

Make a function which has a UI update code, write it in displayChat(View view) 创建一个具有UI更新代码的函数,将其写入displayChat(View view)

Like, 喜欢,

public void displayChat(View view) 
{
     updateUI();
}

Update: 更新:

However, when I click on Chat, I am getting the following error :: Unfortunately My Fist App has stopped working

Are you sure you have inserted DisplayMessageActivity in activity tag of AndroidManifest.xml file. 您确定已在AndroidManifest.xml文件的activity tag中插入DisplayMessageActivity

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

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