开发者

My app crashes in landscape mode

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 retrie开发者_Go百科veStream(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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜