fixed nullpointer at startup
This commit is contained in:
parent
d4ff257994
commit
5fd1e2e734
3 changed files with 24 additions and 2 deletions
|
@ -3,6 +3,8 @@ package btools.routingapp;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
@ -61,8 +63,20 @@ public class AppLogger
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ public class BRouterActivity extends Activity implements OnInitListener {
|
||||||
|
|
||||||
// instantiate our simulation view and set it as the activity's content
|
// instantiate our simulation view and set it as the activity's content
|
||||||
mBRouterView = new BRouterView(this);
|
mBRouterView = new BRouterView(this);
|
||||||
|
mBRouterView.init();
|
||||||
setContentView(mBRouterView);
|
setContentView(mBRouterView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,10 @@ public class BRouterView extends View
|
||||||
|
|
||||||
public BRouterView(Context context) {
|
public BRouterView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
imgw = metrics.widthPixels;
|
imgw = metrics.widthPixels;
|
||||||
|
@ -218,6 +221,10 @@ public class BRouterView extends View
|
||||||
String msg = e instanceof IllegalArgumentException
|
String msg = e instanceof IllegalArgumentException
|
||||||
? e.getMessage() + ( cor == null ? "" : " (coordinate-source: " + cor.basedir + cor.rootdir + ")" )
|
? e.getMessage() + ( cor == null ? "" : " (coordinate-source: " + cor.basedir + cor.rootdir + ")" )
|
||||||
: e.toString();
|
: e.toString();
|
||||||
|
|
||||||
|
AppLogger.log( msg );
|
||||||
|
AppLogger.log( AppLogger.formatThrowable( e ) );
|
||||||
|
|
||||||
((BRouterActivity)getContext()).showErrorMessage( msg );
|
((BRouterActivity)getContext()).showErrorMessage( msg );
|
||||||
}
|
}
|
||||||
waitingForSelection = true;
|
waitingForSelection = true;
|
||||||
|
|
Loading…
Reference in a new issue