傢伙,我需要在這你的幫助時,我創建了一個應用程序有3個活動(主,線性和表)它們如下所示我的應用程序崩潰,每次我從一個活動移到另一個
MainActivity:
package com.hossa.layoutapp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button Submit1,Table1,Linear1;
EditText Name1,Email1,Phone1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Submit1=(Button)findViewById(R.id.RelativeSubmit);
Table1=(Button)findViewById(R.id.RelativeTable);
Linear1=(Button)findViewById(R.id.RelativeLinear);
Name1=(EditText)findViewById(R.id.Name1);
Email1=(EditText)findViewById(R.id.Email1);
Phone1=(EditText)findViewById(R.id.Phone1);
Submit1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//providing the user with help explaination//
Context context=getApplicationContext();
String message1="your data is submitted";
int Duration=Toast.LENGTH_LONG;
Toast t=Toast.makeText(context,message1, Duration);
t.show();
}
});
Table1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(MainActivity.this,TableActivity.class);
startActivity(i);
}
});
Linear1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(MainActivity.this,LinearActivity.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;
}
}
下面
是LinearActivity:
package com.hossa.layoutapp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LinearActivity {
public class MainActivity extends Activity {
Button Submit2,Table2,Relative1;
EditText Name2,Email2,Phone2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.linearlayout);
Submit2=(Button)findViewById(R.id.LinearSubmit);
Table2=(Button)findViewById(R.id.LinearTable);
Relative1=(Button)findViewById(R.id.LinearRelative);
Name2=(EditText)findViewById(R.id.Name2);
Email2=(EditText)findViewById(R.id.Email2);
Phone2=(EditText)findViewById(R.id.Phone2);
Submit2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//providing the user with help explaination//
Context context=getApplicationContext();
String message1="your data is submitted";
int Duration=Toast.LENGTH_LONG;
Toast t=Toast.makeText(context,message1, Duration);
t.show();
}
});
Table2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent j=new Intent(getApplicationContext(),TableActivity.class);
startActivity(j);
}
});
Relative1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent k=new Intent(getApplicationContext(),MainActivity.class);
startActivity(k);
}
});
}
@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;
}
}
}
最後是表活動:
package com.hossa.layoutapp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class TableActivity {
public class MainActivity extends Activity {
Button Submit3,Relative2,Linear2;
EditText Name3,Email3,Phone3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tablelayout);
Submit3=(Button)findViewById(R.id.TableSubmit);
Relative2=(Button)findViewById(R.id.TableRelative);
Linear2=(Button)findViewById(R.id.TableLinear);
Name3=(EditText)findViewById(R.id.Name3);
Email3=(EditText)findViewById(R.id.Email3);
Phone3=(EditText)findViewById(R.id.Phone3);
Submit3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//providing the user with help explaination//
Context context=getApplicationContext();
String message1="your data is submitted";
int Duration=Toast.LENGTH_LONG;
Toast t=Toast.makeText(context,message1, Duration);
t.show();
}
});
Linear2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent j=new Intent(getApplicationContext(),LinearActivity.class);
startActivity(j);
}
});
Relative2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent k=new Intent(getApplicationContext(),MainActivity.class);
startActivity(k);
}
});
}
@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;
}
}
}
的清單文件:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.hossa.layoutapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.hossa.layoutapp.LinearActivity"
android:label="@string/app_name"
>
</activity>
<activity
android:name="com.hossa.layoutapp.TableActivity"
android:label="@string/app_name"
>
</activity>
</application>
</manifest>
要做的主要事情是推動上的按鈕,並移動到下一個活動,但它總是崩潰。 ..請幫助thx
從崩潰中發佈logcat – codeMagic