2014-12-07 66 views
0

我一直在尋找對這個問題有很多張貼了這個問題之前,但仍不可能得到任何幫助後打開,請幫我解決這個問題,當我按下按鈕黑色頁面出現,然後應用程序關閉,說它沒有響應,即時通訊新手在這裏和任何形式的幫助將不勝感激。次活動doesent點擊按鈕

activity_main
<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" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.firstapp.MainActivity" > 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView1" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="26dp" 
    android:ems="10" 
    android:inputType="numberPassword" /> 

<EditText 
    android:id="@+id/editText5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText1" 
    android:layout_alignLeft="@+id/editText1" 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text="Enter your Password" 
    tools:ignore="HardcodedText" /> 

<EditText 
    android:id="@+id/editText3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText5" 
    android:layout_alignLeft="@+id/editText5" 
    android:layout_marginBottom="20dp" 
    android:ems="10" 
    android:inputType="textEmailAddress" > 

    <requestFocus android:layout_width="wrap_content" /> 

</EditText> 

<EditText 
    android:id="@+id/editText4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText3" 
    android:layout_alignLeft="@+id/editText3" 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text="Enter your E-mail id" 
    tools:ignore="HardcodedText" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/editText4" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="36dp" 
    android:src="@drawable/robo" 
    android:contentDescription="@null"/> 

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="38dp" 
    android:ems="10" 
    android:inputType="textMultiLine" 
    android:text="Welcome To Foodparkk" 
    tools:ignore="HardcodedText" /> 

<Button 
    android:id="@+id/button_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="Login" /> 

</RelativeLayout> 

MainActivity.java
package com.example.firstapp; 

import com.example.firstapp.R; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    final Button button = (Button) findViewById(R.id.button_id); 
    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent i = new Intent(getApplicationContext(),Second.class); 
      startActivity(i); 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
    } 
} 

Second.java
package com.example.firstapp; 

    import android.support.v7.app.ActionBarActivity; 
    import android.os.Bundle; 
    import android.view.Menu; 
    import android.view.MenuItem; 

    public class Second extends ActionBarActivity { 

    @Override 
     protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_second); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.second, menu); 
    return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
    } 
} 

Activity_Second.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" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.firstapp.Second" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 
    </RelativeLayout> 

清單代碼

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.firstapp" 
android:versionCode="1" 
android:versionName="1.0" > 

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

<application 
    android:allowBackup="true" 
    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=".Second" 
     android:label="@string/title_activity_second" > 
     </activity> 
    </application> 

    </manifest> 
+0

請張貼代碼'秒'活動 – 2014-12-07 19:17:41

+0

類型你得到了錯誤... – 2014-12-07 19:20:37

+0

第一XML頁面打開了,同時運行的應用程序,但只要我按下登錄按鈕的應用程序關閉並稱應用程序沒有響應 – Shashwat 2014-12-07 19:23:16

回答

1
public class MainActivity extends ActionBarActivity { //mainactivity class 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
Button button = (Button) findViewById(R.id.button_id); 
button.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
     Intent i = new Intent(MainActivity.this,Second.class); 
     startActivity(i); 
     } 
    }); 
} 

那麼你的清單

<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/Theme.Base.AppCompat.Light.DarkActionBar" > // i changed this 
<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=".Second" 
    android:label="@string/title_activity_second" > 
    </activity> 
</application> 
如果擴展actionbarActivity其XML應該使用它的風格的,我不wona故事這一點,所以我會repharse它在我的編輯

。簡單地說,你的第二個活動不會有風格的設定所以它使用設備的默認主題在你的應用程序設置成複製礦山各自的代碼粘貼到你的活動

+0

感謝Elltz .. !! – Shashwat 2014-12-07 19:47:58

-2

它被稱爲ANR short for Android Not Responding。你的應用在主線程中做了很多處理。考慮使用後臺線程或AsyncTask以及ProgressDialog,以便主線程不受處理部分的影響。

Read more關於它的文檔。有關更多信息,另請參閱this post