fixed nullpointer at startup

This commit is contained in:
Arndt 2014-07-30 08:19:45 +02:00
parent d4ff257994
commit 5fd1e2e734
3 changed files with 24 additions and 2 deletions

View file

@ -3,6 +3,8 @@ package btools.routingapp;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import android.os.Environment;
@ -61,8 +63,20 @@ public class AppLogger
}
catch( IOException e )
{
throw new RuntimeException( "cannot write appdebug.txt: " + e );
throw new RuntimeException( "cannot write brouterapp.txt: " + e );
}
}
}
/**
* Format an exception using
*/
public static String formatThrowable( Throwable t )
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter( sw );
t.printStackTrace( pw );
return sw.toString();
}
}

View file

@ -56,6 +56,7 @@ public class BRouterActivity extends Activity implements OnInitListener {
// instantiate our simulation view and set it as the activity's content
mBRouterView = new BRouterView(this);
mBRouterView.init();
setContentView(mBRouterView);
}

View file

@ -83,7 +83,10 @@ public class BRouterView extends View
public BRouterView(Context context) {
super(context);
}
public void init()
{
DisplayMetrics metrics = new DisplayMetrics();
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
imgw = metrics.widthPixels;
@ -218,6 +221,10 @@ public class BRouterView extends View
String msg = e instanceof IllegalArgumentException
? e.getMessage() + ( cor == null ? "" : " (coordinate-source: " + cor.basedir + cor.rootdir + ")" )
: e.toString();
AppLogger.log( msg );
AppLogger.log( AppLogger.formatThrowable( e ) );
((BRouterActivity)getContext()).showErrorMessage( msg );
}
waitingForSelection = true;