我的应用程序在横向模式下崩溃
我的 Android 应用程序有问题:
我的应用程序是一个 tabhost,具有三列、两个普通视图和一个列表视图。 当我更改平板电脑的方向时,我的应用程序崩溃了。我尝试了不同的方法,得到了一个解决方案,但这不是一个好的解决方案。
我将其放入清单中:android:configChanges="keyboardHidden|orientation"
。 使用此解决方案,当我更改方向时,我的应用程序不会崩溃,但我有两个新问题,其中之一是我无法以横向模式启动应用程序,因为如果我将平板电脑置于水平模式,我的应用程序就会崩溃。
另一个问题是: 我的应用程序不会将布局更改为横向。当我更改方向时,我的应用程序会自动放入正常布局,但水平布局。
这是 logcat 输出:
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): FATAL EXCEPTION: main
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.main}: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.activityDatos}: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.os.Looper.loop(Looper.java:123)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at java.lang.reflect.Method.invokeNative(Native Method)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at java.lang.reflect.Method.invoke(Method.java:521)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at dalvik.system.NativeStart.main(Native Method)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.activityDatos}: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at org.vicomtech.edonontv.main.onCreate(main.java:77)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): ... 11 more
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): Caused by: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at org.vicomtech.edonontv.activityDatos.onCreate(activityDatos.java:140)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): ... 19 more
和主程序:
public class main extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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, activityPartido.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Videos").setIndicator("Bideoak",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, activityLista.class);
spec = tabHost.newTabSpec("Sarea").setIndicator("Sarea",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, activityDatos.class);
spec = tabHost.newTabSpec("Datuak").setIndicator("Datuak",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
以及 ActivityDatos 的一部分:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitydatos);
refresh = new RefreshHandler();
updateUI();
private String retrieveStream(String url) {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = null;
try {
response = client.execute(request);
} catch (ClientProtocolException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
String html = "";
InputStream in = null;
try {
in = response.getEntity().getContent();
} catch (IllegalStateException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
} catch (IOException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
StringBuilder str =null;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} catch (IOException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
html = str.toString();
return html;
感谢您所做的一切
I have a problem with my Android app:
My app is a tabhost that has three columns, two normal views and a listview.
My app crashes when I change the orietation of my tablet. I tried different things, and I get a solution, but it isn't a good one.
I put this in the manifest: android:configChanges="keyboardHidden|orientation"
.
With this solution my app doesn't crash when I change the orientation, but I have two new problems, one of them is that I can't start the app in landscape mode, because if I have the tablet in horizontal mode my app crashes.
And the other problem is:
my app doesn't change the layout to landscape. When I change the orientation my app automatically put in the normal layout but in horizontal.
Here is the logcat output:
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): FATAL EXCEPTION: main
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.main}: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.activityDatos}: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.os.Looper.loop(Looper.java:123)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at java.lang.reflect.Method.invokeNative(Native Method)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at java.lang.reflect.Method.invoke(Method.java:521)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at dalvik.system.NativeStart.main(Native Method)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.vicomtech.edonontv/org.vicomtech.edonontv.activityDatos}: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at org.vicomtech.edonontv.main.onCreate(main.java:77)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): ... 11 more
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): Caused by: java.lang.NullPointerException
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at org.vicomtech.edonontv.activityDatos.onCreate(activityDatos.java:140)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-24 09:09:56.624: ERROR/AndroidRuntime(3010): ... 19 more
and the main program:
public class main extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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, activityPartido.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Videos").setIndicator("Bideoak",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, activityLista.class);
spec = tabHost.newTabSpec("Sarea").setIndicator("Sarea",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, activityDatos.class);
spec = tabHost.newTabSpec("Datuak").setIndicator("Datuak",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
and a part of activityDatos:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitydatos);
refresh = new RefreshHandler();
updateUI();
private String retrieveStream(String url) {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = null;
try {
response = client.execute(request);
} catch (ClientProtocolException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
String html = "";
InputStream in = null;
try {
in = response.getEntity().getContent();
} catch (IllegalStateException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
} catch (IOException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
StringBuilder str =null;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} catch (IOException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
Log.w(NOTIFICATION_SERVICE, e);
e.printStackTrace();
}
html = str.toString();
return html;
thanks for everything
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论