Error while trying to upload image to facebook - java

I am trying to upload image to Facebook using facebook api.
But getting error please find the code below.
I am unable to find out the error. I tried debugging it but am unable to understand the error looking at the log cat. Please help experts. Thanks in advance.
public void postImageonWall(Bitmap bmpImg) {
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmpImg.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
try {
facebook.request(params);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Log Cat:
05-30 05:55:52.489: E/AndroidRuntime(1220): FATAL EXCEPTION: main
05-30 05:55:52.489: E/AndroidRuntime(1220): java.lang.NullPointerException
05-30 05:55:52.489: E/AndroidRuntime(1220): at libcore.net.UriCodec.encode(UriCodec.java:132)
05-30 05:55:52.489: E/AndroidRuntime(1220): at java.net.URLEncoder.encode(URLEncoder.java:50)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Util.encodeUrl(Util.java:85)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Util.openUrl(Util.java:145)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Facebook.request(Facebook.java:717)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.facebook.android.Facebook.request(Facebook.java:633)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.example.dragview.DragActivity.postImageonWall(DragActivity.java:458)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.example.dragview.DragActivity.onOptionsItemSelected(DragActivity.java:428)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:372)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivity.superOnMenuItemSelected(ActionBarActivity.java:244)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivityDelegateICS.onMenuItemSelected(ActionBarActivityDelegateICS.java:165)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:130)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onMenuItemSelected(ActionBarActivityDelegateICS.java:300)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.view.View.performClick(View.java:4204)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.view.View$PerformClick.run(View.java:17355)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.os.Handler.handleCallback(Handler.java:725)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.os.Looper.loop(Looper.java:137)
05-30 05:55:52.489: E/AndroidRuntime(1220): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-30 05:55:52.489: E/AndroidRuntime(1220): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 05:55:52.489: E/AndroidRuntime(1220): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 05:55:52.489: E/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-30 05:55:52.489: E/AndroidRuntime(1220): at dalvik.system.NativeStart.main(Native Method)

Related

Fragment did not create a view after rotating device

I am trying to make a 2 fragments screen in the tablet view but it's crashing after rotating the device.
This is layout-sw600dp/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:id="#+id/main_activity"
android:orientation="horizontal"
tools:context="com.morxander.popularmovies.MainActivity">
<fragment
android:id="#+id/fragment_main"
android:name="com.morxander.popularmovies.MainActivity$PlaceholderFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
tools:layout="#layout/fragment_main" />
<FrameLayout
android:id="#+id/movie_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
And this is the related part of the code :
private static boolean mTwoPane;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (findViewById(R.id.movie_detail_container) != null) {
mTwoPane = true;
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_main, new PlaceholderFragment())
.commit();
}else{
mTwoPane = false;
}
}
}
.....
.....
.....
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
setHasOptionsMenu(true);
// Method to set the views controls
initComponents(rootView);
return rootView;
And when I rotate the device the app crashes and gives me the following error :
08-10 21:22:34.842: E/AndroidRuntime(4338): FATAL EXCEPTION: main
08-10 21:22:34.842: E/AndroidRuntime(4338): Process: com.morxander.popularmovies, PID: 4338
08-10 21:22:34.842: E/AndroidRuntime(4338): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.morxander.popularmovies/com.morxander.popularmovies.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3912)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread.access$900(ActivityThread.java:144)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.os.Handler.dispatchMessage(Handler.java:102)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.os.Looper.loop(Looper.java:135)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread.main(ActivityThread.java:5221)
08-10 21:22:34.842: E/AndroidRuntime(4338): at java.lang.reflect.Method.invoke(Native Method)
08-10 21:22:34.842: E/AndroidRuntime(4338): at java.lang.reflect.Method.invoke(Method.java:372)
08-10 21:22:34.842: E/AndroidRuntime(4338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-10 21:22:34.842: E/AndroidRuntime(4338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-10 21:22:34.842: E/AndroidRuntime(4338): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
08-10 21:22:34.842: E/AndroidRuntime(4338): at com.morxander.popularmovies.MainActivity.onCreate(MainActivity.java:38)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.Activity.performCreate(Activity.java:5937)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
08-10 21:22:34.842: E/AndroidRuntime(4338): ... 11 more
08-10 21:22:34.842: E/AndroidRuntime(4338): Caused by: java.lang.IllegalStateException: Fragment com.morxander.popularmovies.MainActivity$PlaceholderFragment did not create a view.
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2199)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.support.v7.app.ActionBarActivity.onCreateView(ActionBarActivity.java:543)
08-10 21:22:34.842: E/AndroidRuntime(4338): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
08-10 21:22:34.842: E/AndroidRuntime(4338): ... 21 more
}
I tried many solutions but nothing is working for me.
Try to check the layout passed in the statement
View rootView = inflater.inflate(R.layout.fragment_main, container, false);

How to store a single row data into a string array of sqlite database in android

I have called a function returnCurrentNameById() by passing the id of the particular row. But it gives an error.
String[] s1;
public String[] returnCurrentNameById(int k) throws SQLException{
String[] columns = new String[]{ KEY_ID1, KEY_NAME, Key_DOB, KEY_AGE, KEY_PHONE_NO, Key_EXPERIENCE, KEY_EMAIL, KEY_STATUS, KEY_STATUS};
SQLiteDatabase db3 = this.getReadableDatabase();
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + "=" + k, null, null, null, null);
if (c != null){
c.moveToFirst();
for(int i = 0; i<=8; i++){
s1[i] = c.getString(i);
}
return s1;
}
return null;
}
The Log cat error report is:
02-15 16:38:13.424 1545-1545/world.com.my`enter code here`progect09 D/AndroidRuntime﹕ Shutting down VM
02-15 16:38:13.464 1545-1545/world.com.myprogect09 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
02-15 16:38:13.533 1545-1545/world.com.myprogect09 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3591)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3586)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16966)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at world.com.myprogect09.DataBaseSQL.returnCurrentNameById1(DataBaseSQL.java:209)
at world.com.myprogect09.ThirdActivity.isClicked(ThirdActivity.java:74)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3586)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16966)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
02-15 16:38:34.491 1545-1545/world.com.myprogect09 I/Process﹕ Sending signal. PID: 1545 SIG: 9
You have not initialized your s1 array.
Use
s1 = new String[9];
to allocate an array of 9 elements.
Also check the return value of moveToFirst() so you don't get an exception in case the query returns no rows.
Replace
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + "=" + k, null, null, null, null);
with
Cursor c = db3.query(DATA_BASE_TABLE_NAME1, columns, KEY_ID1 + " = ?", new String[]{String.valueOf(k)}, null, null, null);

Intent is not passing

I having a problem in passing the intent. The code is written in proper manner still it is showing errors in the logcat. Any help will be greatfull. Thank you
Have i placed the intent code in the write area???
Here is my main file.
MainActivity.java
public class MainActivity extends Activity {
ProgressBar progressBar;
int progressStatus = 0;
TextView textView1, textView2;
Handler handler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
textView2 = (TextView) findViewById(R.id.load_per);
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView2.setText(progressStatus + "%");
if (progressStatus == 100) {
Intent i = new Intent(MainActivity.this,
EventActivity.class);
startActivity(i);
}
}
});
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
The logcat is showing errors like this
05-30 13:39:51.296: E/AndroidRuntime(1352): FATAL EXCEPTION: main
05-30 13:39:51.296: E/AndroidRuntime(1352): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.temp9/com.example.temp9.EventActivity}: java.lang.NullPointerException
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.os.Looper.loop(Looper.java:137)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.ActivityThread.main(ActivityThread.java:4340)
05-30 13:39:51.296: E/AndroidRuntime(1352): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 13:39:51.296: E/AndroidRuntime(1352): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 13:39:51.296: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 13:39:51.296: E/AndroidRuntime(1352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 13:39:51.296: E/AndroidRuntime(1352): at dalvik.system.NativeStart.main(Native Method)
05-30 13:39:51.296: E/AndroidRuntime(1352): Caused by: java.lang.NullPointerException
05-30 13:39:51.296: E/AndroidRuntime(1352): at com.example.temp9.EventActivity.onCreate(EventActivity.java:22)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.Activity.performCreate(Activity.java:4465)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-30 13:39:51.296: E/AndroidRuntime(1352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
05-30 13:39:51.296: E/AndroidRuntime(1352): ... 11 more
Problem is Caused by: java.lang.NullPointerException
Here com.example.temp9.EventActivity.onCreate(EventActivity.java:22) in EventActivity class' onCreate function at line 22 location you are accessing some null pointer.
Seems like you haven't added EventActivity in AndroidManifest.xml(failed to start activity message in logcat). Make sure you have added the activity in Manifest file.

Zoom in to markers google map V2

I have an ArrayList of a custom object with lat and long properties.
I have managed to put markers on the map. What I want is to be able to zoom in to those markers when the map loads.
What I have tried below causes the app to crash.
Here is the code for loading the map:
public void getBridgeData() {
db = new DbHelperClass(this);
bridges = db.getAllBridges();
DecimalFormat dc = new DecimalFormat("#.000");
Builder builder = new LatLngBounds.Builder();
for (int i= 0;i<bridges.size();i++) {
Bridge b= (Bridge)bridges.get(i);
double lati= b.getLatitude();
double longo= b.getLongitude();
double reflat= b.getReflat();
double reflong= b.getReflong();
LatLng start = new LatLng(reflat,reflong);
LatLng end = new LatLng(lati,longo);
GeneralUtils uts = new GeneralUtils();
double ch= uts.calculateDistance(start, end);
String chainage = dc.format(ch);
String mysnipet = "Location:" + b.getRoadname() + " " + chainage;
Marker mm=map.addMarker(new
MarkerOptions().position(new LatLng(lati, longo))
.title(b.getBridgename())
.snippet(mysnipet));
builder.include(mm.getPosition());
}
LatLngBounds bounds= builder.build();
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 15));
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
Here also part of the code
public class MainActivity extends FragmentActivity {
private GoogleMap map;
private DbHelperClass db;
private List<Bridge> bridges = new ArrayList<Bridge>();
CameraUpdate cu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_map);
//AddSomeData();
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if(map!=null) {
getBridgeData();
}
}
}
Here is the error log:
05-30 22:19:28.894: E/AndroidRuntime(5593): FATAL EXCEPTION: main
05-30 22:19:28.894: E/AndroidRuntime(5593): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bridge.bridgeinventory/com.bridge.bridgeinventory.MainActivity}: java.lang.IllegalStateException: Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1755)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1774)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.ActivityThread.access$1500(ActivityThread.java:157)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1001)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.os.Handler.dispatchMessage(Handler.java:130)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.os.Looper.loop(SourceFile:351)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.ActivityThread.main(ActivityThread.java:3841)
05-30 22:19:28.894: E/AndroidRuntime(5593): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 22:19:28.894: E/AndroidRuntime(5593): at java.lang.reflect.Method.invoke(Method.java:538)
05-30 22:19:28.894: E/AndroidRuntime(5593): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
05-30 22:19:28.894: E/AndroidRuntime(5593): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
05-30 22:19:28.894: E/AndroidRuntime(5593): at dalvik.system.NativeStart.main(Native Method)
05-30 22:19:28.894: E/AndroidRuntime(5593): Caused by: java.lang.IllegalStateException: Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.
05-30 22:19:28.894: E/AndroidRuntime(5593): at kbh.b(Unknown Source)
05-30 22:19:28.894: E/AndroidRuntime(5593): at mas.a(Unknown Source)
05-30 22:19:28.894: E/AndroidRuntime(5593): at mal.a(Unknown Source)
05-30 22:19:28.894: E/AndroidRuntime(5593): at mbi.a(Unknown Source)
05-30 22:19:28.894: E/AndroidRuntime(5593): at fms.onTransact(SourceFile:83)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.os.Binder.transact(Binder.java:310)
05-30 22:19:28.894: E/AndroidRuntime(5593): at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.moveCamera(Unknown Source)
05-30 22:19:28.894: E/AndroidRuntime(5593): at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source)
05-30 22:19:28.894: E/AndroidRuntime(5593): at com.bridge.bridgeinventory.MainActivity.getBridgeData(MainActivity.java:148)
05-30 22:19:28.894: E/AndroidRuntime(5593): at com.bridge.bridgeinventory.MainActivity.onCreate(MainActivity.java:44)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
05-30 22:19:28.894: E/AndroidRuntime(5593): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1719)
05-30 22:19:28.894: E/AndroidRuntime(5593): ... 11 more
How can I make it work?
The problem is that the map is not loaded yet to the layout that is why you got that error
Solution:
map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
#Override
public void onMapLoaded() {
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 15));
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
});
It will call that method when the map is already loaded to the layout.

Android Socket fatal error

My issue is pretty same that this one, but I'm not creating any output streams yet
FATAL Exception Main android
// Try to connect
try {
// Check the network state
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
// If there is conection, try to create a socket with remote server
if (networkInfo.isConnected()) {
InetAddress address = InetAddress
.getByName(serverAdressTextField.getText().toString());
Socket serverConnection = new Socket(address, PORT);
// Write message of success
//TODO Implement the rest of login function
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
} else {
// Say user that there is no internet
Toast.makeText(this, "No connection", Toast.LENGTH_SHORT)
.show();
}
// Catch unknown host and prompt error
} catch (UnknownHostException e) {
Toast.makeText(this, "Server is not reached", Toast.LENGTH_SHORT)
.show();
return;
// Prompt IO exception
} catch (IOException e) {
Toast.makeText(this, "I/O Error", Toast.LENGTH_SHORT).show();
return;
// Any other exception, not good
} catch (Exception e) {
Toast.makeText(this, "Unknown Error", Toast.LENGTH_SHORT).show();
return;
}
It throws IllegalStateException and If not catched it gives that
02-17 05:29:59.655: E/AndroidRuntime(18470): FATAL EXCEPTION: main
02-17 05:29:59.655: E/AndroidRuntime(18470): java.lang.IllegalStateException: Could not execute method of the activity
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.view.View$1.onClick(View.java:3591)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.view.View.performClick(View.java:4084)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.view.View$PerformClick.run(View.java:16966)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.os.Handler.handleCallback(Handler.java:615)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.os.Handler.dispatchMessage(Handler.java:92)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.os.Looper.loop(Looper.java:137)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 05:29:59.655: E/AndroidRuntime(18470): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-17 05:29:59.655: E/AndroidRuntime(18470): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-17 05:29:59.655: E/AndroidRuntime(18470): at dalvik.system.NativeStart.main(Native Method)
02-17 05:29:59.655: E/AndroidRuntime(18470): Caused by: java.lang.reflect.InvocationTargetException
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.view.View$1.onClick(View.java:3586)
02-17 05:29:59.655: E/AndroidRuntime(18470): ... 11 more
02-17 05:29:59.655: E/AndroidRuntime(18470): Caused by: android.os.NetworkOnMainThreadException
02-17 05:29:59.655: E/AndroidRuntime(18470): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
02-17 05:29:59.655: E/AndroidRuntime(18470): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
02-17 05:29:59.655: E/AndroidRuntime(18470): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
02-17 05:29:59.655: E/AndroidRuntime(18470): at libcore.io.IoBridge.connect(IoBridge.java:112)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.net.Socket.startupSocket(Socket.java:566)
02-17 05:29:59.655: E/AndroidRuntime(18470): at java.net.Socket.<init>(Socket.java:225)
02-17 05:29:59.655: E/AndroidRuntime(18470): at com.snivik.morze.LoginWindow.connectToServer(LoginWindow.java:62)
02-17 05:29:59.655: E/AndroidRuntime(18470): ... 14 more
Your problem is that you are obviously trying to open a socket in the main thread, that's why you are getting android.os.NetworkOnMainThreadException.
All networking has to be done in a background thread.

Categories