我制作了4个布局,它们是小型,普通,大型和xlarge布局,我使用的是Android 2.3和HostTab活动,当我在具有小型,普通和大型布局的设备上运行时,它工作正常,但是当我进入xlarge布局(10.1)它在tabhost中崩溃。我不确定,但我猜TabHost有不同布局的问题,这个logcat:
07-23 08:01:24.099: E/AndroidRuntime(9505): FATAL EXCEPTION: main
07-23 08:01:24.099: E/AndroidRuntime(9505): java.lang.RuntimeException: Unable to start activity ComponentInfo{id.co.ajsmsig/id.co.ajsmsig.epolicy.EpolicyMainTab}: java.lang.RuntimeException: Unable to start activity ComponentInfo{id.co.ajsmsig/id.co.ajsmsig.epolicy.EpolicyListPolis}: java.lang.NullPointerException
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.os.Looper.loop(Looper.java:137)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.main(ActivityThread.java:4895)
07-23 08:01:24.099: E/AndroidRuntime(9505): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 08:01:24.099: E/AndroidRuntime(9505): at java.lang.reflect.Method.invoke(Method.java:511)
07-23 08:01:24.099: E/AndroidRuntime(9505): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
07-23 08:01:24.099: E/AndroidRuntime(9505): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
07-23 08:01:24.099: E/AndroidRuntime(9505): at dalvik.system.NativeStart.main(Native Method)
07-23 08:01:24.099: E/AndroidRuntime(9505): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{id.co.ajsmsig/id.co.ajsmsig.epolicy.EpolicyListPolis}: java.lang.NullPointerException
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1938)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:705)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.widget.TabHost.setCurrentTab(TabHost.java:369)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.widget.TabHost.addTab(TabHost.java:247)
07-23 08:01:24.099: E/AndroidRuntime(9505): at id.co.ajsmsig.epolicy.EpolicyMainTab.onCreate(EpolicyMainTab.java:44)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.Activity.performCreate(Activity.java:5163)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
07-23 08:01:24.099: E/AndroidRuntime(9505): ... 11 more
07-23 08:01:24.099: E/AndroidRuntime(9505): Caused by: java.lang.NullPointerException
07-23 08:01:24.099: E/AndroidRuntime(9505): at id.co.ajsmsig.epolicy.EpolicyListPolis.onCreate(EpolicyListPolis.java:82)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.Activity.performCreate(Activity.java:5163)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-23 08:01:24.099: E/AndroidRuntime(9505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
07-23 08:01:24.099: E/AndroidRuntime(9505): ... 21 more
这是我的EpolicyMainTab.java:
@SuppressWarnings("deprecation")
public class EpolicyMainTab extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
//hide title bar
BasicDisplaySettings.toggleTaskBar(EpolicyMainTab.this, false);
//show status bar
BasicDisplaySettings.toggleStatusBar(EpolicyMainTab.this, true);
super.onCreate(savedInstanceState);
setContentView(R.layout.epolicy);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, EpolicyListPolis.class);
spec = tabHost.newTabSpec("Home").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_home))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, NABActivity.class);
spec = tabHost.newTabSpec("NAB").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_nab))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ContactActivity.class);
spec = tabHost.newTabSpec("Contact").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_contact))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, AgenActivity.class);
spec = tabHost.newTabSpec("Agen").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_agen))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, EpolicyBantuan.class);
spec = tabHost.newTabSpec("Bantuan").setIndicator("",
res.getDrawable(R.drawable.epolicy_menu_xml_bantuan))
.setContent(intent);
tabHost.addTab(spec);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){
tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0);
tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);
}
tabHost.setCurrentTab(0);
}
@Override
public void onBackPressed() {
finish();
}
}
这是我的EpolicyListPolis:
public class EpolicyListPolis extends ListActivity {
static String PEMEGANG="PEMEGANG";
static String POLIS="POLIS";
static String STATUS="STATUS";
static String TERTANGGUNG="TERTANGGUNG";
String KEY, strUser;
private ArrayList<ListPolis>NasabahList;
ListView list;
private ProgressDialog Dialog;
private String strStoragePath = "",
strNameFileDiv = "";
ImageView LogoutButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.Nomor_Polis);
setContentView(R.layout.epolicy_list_polis)
SharedPreferences settings = getSharedPreferences("PREFS_NAME", 0);
strUser= settings.getString("etUser", null);
KEY = settings.getString("key", null);
//Related to storage
strStoragePath = getResources().getString(R.string.storagepath);
strNameFileDiv = getResources().getString(R.string.filediv);
LogoutButton=(ImageView)findViewById(R.id.LogoutButton);
NasabahList= new ArrayList<ListPolis>();
new NasabahAsyncTask().execute();
LogoutButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
dialogSignOut();
}
});
}
public class NasabahAsyncTask extends AsyncTask<Void, Void, String>{
String url = ("http://www.abc.xyz"+strUser+"&k="+KEY);
public NasabahAsyncTask() {
this.url=url;
// TODO Auto-generated constructor stub
}
protected void onPreExecute() {
super.onPreExecute();
Dialog = ProgressDialog.show(EpolicyListPolis.this, "", "Melakukan Pengambilan Data");
}
@Override
protected String doInBackground(Void... params) {
String result="";
try {
result=Connection.get(url);
System.out.println(url);
}catch (Exception e){
result=" ";
Log.d("test viewer",e.getMessage());
}
return result;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
fetchResponse(result.replace("\n", "").trim());
Dialog.dismiss();
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String POLIS = ((TextView)view.findViewById(R.id.polis)).getText().toString();
SharedPreferences settings = getSharedPreferences("PREFS_NAME", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("POLIS", POLIS);
editor.commit();
Intent in = new Intent(EpolicyListPolis.this, EpolicyTabKategori.class);
startActivity(in);
}
});
}
}
private void fetchResponse(String result) {
// TODO Auto-generated method stub
if (!result.equals("")) {
try {
JSONArray jsonArray = new JSONArray(result);
ListPolis lp=null;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
lp= new ListPolis(jsonObject.optString("POLIS"),
jsonObject.optString("PEMEGANG"),
jsonObject.optString("TERTANGGUNG"),
jsonObject.optString("STATUS"));
NasabahList.add(lp);
list=(ListView)findViewById(android.R.id.list);
}
}catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onBackPressed() {
dialogExit();
}
public void dialogExit()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah anda ingin keluar?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent itSplashEnd = new Intent(EpolicyListPolis.this, SplashEnd.class);
//setIntent.addCategory(Intent.CATEGORY_HOME);
itSplashEnd.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
itSplashEnd.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(itSplashEnd);
finish();
System.exit(0);
}
})
.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void dialogSignOut()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah anda ingin sign-out?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SharedPreferences settings =getSharedPreferences("PREFS_NAME", 0);;
settings.edit().clear().commit();
Intent itSignOut = new Intent(EpolicyListPolis.this, EpolicyMainActivity.class);
itSignOut.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(itSignOut);
finish();
}
})
.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="id.co.ajsmsig"
android:versionCode="2"
android:versionName="1.1"
xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:debuggable="true" >
<activity
android:name=".epolicy.SplashEpolicy"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".epolicy.SplashEnd"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".epolicy.EpolicyMainActivity"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.EpolicyMainTab"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.EpolicyTabKategori"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabPPEpolicy"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabTTEpolicy"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabDatAsu"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabManfaat"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabInvestasi"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabStatus"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabRekening"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.TabNabDetail"
android:label="@string/app_name"
android:uiOptions="splitActionBarWhenNarrow"
></activity>
<activity
android:name=".epolicy.SplashOutActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.NABActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.NABActivityDetail"
android:label="@string/NAB_detail"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.TabelNABDetail"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.ContactActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.AgenActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.EpolicyFaq"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.EpolicyBantuan"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.EpolicyIstilah"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.EpolicyPanduan"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.EpolicyListPolis"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.KategoriNomorPolis"
android:label="@string/kategori_polis"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.PPViewerEpolicy"
android:label="@string/pp"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.TTViewerEpolicy"
android:label="@string/tt"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.RekViewerEpolicy"
android:label="@string/Rekening"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.DatAsuViewerEpolicy"
android:label="@string/Dat_asu"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.ManfaatViewerEpolicy"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.InvestasiViewerEpolicy"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
<activity
android:name=".epolicy.StatusViewerEpolicy"
android:label="@string/app_name"
android:screenOrientation="portrait"
></activity>
</application>
</manifest>
我不知道为什么我的应用程序在遇到Xlarge布局(10.1)时崩溃并强制关闭,有没有人可以帮我解决我的问题?谢谢