If I start app in portrait mode , it works fine.
But if I start it into landscape mode then it gives nullPointerException
when I try to resize my view by using setLayoutParams
.
piece of code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.companygraph);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
if (display.getWidth() > display.getHeight()) {
changeToLandscape();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
changeToLandscape();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
changeToPortrait();
}
}
public void changeToLandscape() {
//IT GIVES NULLPOINTEREXCEPTION HERE.
plot.setLayoutParams(new LinearLayout.LayoutParams(500, 300));
}
public void changeToPortrait() {
//IT GIVES NULLPOINTEREXCEPTION HERE.
plot.setLayoutParams(new LinearLayout.LayoutParams(300, 500));
}
companygraph.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linearLayout">"
<com.androidplot.xy.XYPlot
android:id="@+id/companyPlot"
android:layout_width="300px"
android:layout_height="500px"
title=""/>
</LinearLayout>
ANY HELP WILL BE LIFE-SAVER !!!