Found the problem, i removed this lines
ActionBar actionBar = getActionBar();
actionBar.hide();
and it worked perfectly well.
题
i have two activities, both uses the Theme.Translucent theme, but one works perfectly well while the other causes the error "Unfortunately, has stopped working"
This is the android manifest xml
<activity
android:name="com.dreama.trafic.SearchActivity"
android:theme="@android:style/Theme.Translucent">
<intent-filter >
<action android:name="com.dreama.trafic.SearchActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.dreama.trafic.ReportActivity"
android:theme="@android:style/Theme.Translucent">
<intent-filter >
<action android:name="com.dreama.trafic.ReportActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This is the layout of the ReportActivity which is the activity that fails when i had this line to its attribute android:theme="@android:style/Theme.Translucent"
<?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"
android:orientation="vertical" >
<EditText
android:id="@+id/post_edit"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/post_label"
android:background="@drawable/editable"
android:ems="10"
android:hint="Update your Traffic situation..."
android:inputType="textMultiLine" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/location_edit"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/location_label"
android:background="@drawable/editable"
android:ems="10"
android:hint="Specify your location..." />
<TextView
android:id="@+id/location_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/post_edit"
android:text="Location:" />
<TextView
android:id="@+id/post_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Report:" />
<TextView
android:id="@+id/category_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/location_edit"
android:text="Choose Category:" />
<Spinner
android:id="@+id/category_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/category_label"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/cancelbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/sendbutton"
android:layout_alignBottom="@+id/sendbutton"
android:layout_alignParentRight="true"
android:layout_marginRight="24dp"
android:text="Cancel" />
<Button
android:id="@+id/sendbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/category_spinner"
android:layout_marginLeft="19dp"
android:layout_marginTop="72dp"
android:text="Send Post" />
</RelativeLayout>
This is the line calling the activity
startActivity(new Intent(HomeActivity.this,ReportActivity.class));
and this is the logcat when i try to call this activity
05-15 18:34:38.642: E/AndroidRuntime(15186): FATAL EXCEPTION: main
05-15 18:34:38.642: E/AndroidRuntime(15186): java.lang.RuntimeException:
05-15 18:34:38.642: E/AndroidRuntime(15186): java.lang.RuntimeException: Unable to
start activity ComponentInfo{com.dreama.trafic/com.dreama.trafic.ReportActivity}:
java.lang.NullPointerException
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-15 18:34:38.642: E/AndroidRuntime(15186): at )
android.app.ActivityThread.access$600(ActivityThread.java:156
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.os.Looper.loop(Looper.java:153)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.ActivityThread.main(ActivityThread.java:5297)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
java.lang.reflect.Method.invokeNative(Native Method)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
java.lang.reflect.Method.invoke(Method.java:511)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
dalvik.system.NativeStart.main(Native
Method)
05-15 18:34:38.642: E/AndroidRuntime(15186): Caused by: java.lang.NullPointerException
05-15 18:34:38.642: E/AndroidRuntime(15186): at
com.dreama.trafic.ReportActivity.onCreate(ReportActivity.java:25)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.Activity.performCreate(Activity.java:5122)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
05-15 18:34:38.642: E/AndroidRuntime(15186): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
05-15 18:34:38.642: E/AndroidRuntime(15186): ... 11 more
This is the ReportActivity.java file
public class ReportActivity extends Activity {
String[] presidents;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.report_layout);
ActionBar actionBar = getActionBar();
actionBar.hide();
presidents = getResources().getStringArray(R.array.presidents_array);
Spinner s1 = (Spinner) findViewById(R.id.category_spinner);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,
presidents);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onNothingSelected(AdapterView<?> arg0) { }
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2,
long arg3) {
// TODO Auto-generated method stub
int index = arg0.getSelectedItemPosition();
Toast.makeText(getBaseContext(),"You have selected item :
"+ presidents[index],Toast.LENGTH_SHORT).show();
}
});
}
}
it should be noted that when i run the SearchActivity, it works perfectly but the ReportActivity is the reverse but if i remove the android:theme line,then the activity would display well
解决方案
Found the problem, i removed this lines
ActionBar actionBar = getActionBar();
actionBar.hide();
and it worked perfectly well.