I'm trying to Insert an event to Calendar Using an Intent with the following code:
package come.jobfinder.dev;
import java.util.Calendar;
import org.junit.Test;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
public class CalendarWrapper extends Activity {
public void syncDataWithCalendar(String workPlace , Calendar date){
//TODO should be a field that user should fill - intreviewLength
int intreviewLength = 60;// set it default to be an hour , will be a field user should fill
//TODO should be a field that will be sent - position
String position = "Product Manager";
//TODO should be a field that will be sent - location
String location = "Tel Aviv";
//TODO need to check where to take this argument from
long calID = 3;
Calendar beginTime = Calendar.getInstance();
beginTime.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR), date.get(Calendar.MINUTE));
Calendar endTime = Calendar.getInstance();
endTime.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR), date.get(Calendar.MINUTE)+intreviewLength);
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
.putExtra(Events.TITLE, "Job Interview with "+workPlace)
.putExtra(Events.DESCRIPTION, "Job interview with "+workPlace+" for the position"+position)
.putExtra(Events.EVENT_LOCATION, location)
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
.putExtra(Intent.EXTRA_EMAIL, "rowan#example.com,trevor#example.com");
startActivity(intent);
//return intent;
// get the event ID that is the last element in the Uri
}
}
and get the following errors:
11-02 21:22:07.580: E/AndroidRuntime(15871): FATAL EXCEPTION: main
11-02 21:22:07.580: E/AndroidRuntime(15871): java.lang.NullPointerException
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.app.Activity.startActivityForResult(Activity.java:3195)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.app.Activity.startActivity(Activity.java:3302)
11-02 21:22:07.580: E/AndroidRuntime(15871): at come.jobfinder.dev.CalendarWrapper.syncDataWithCalendar(CalendarWrapper.java:45)
11-02 21:22:07.580: E/AndroidRuntime(15871): at come.jobfinder.dev.UpdateWorkPlace.onClick(UpdateWorkPlace.java:90)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.view.View.performClick(View.java:3627)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.view.View$PerformClick.run(View.java:14329)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.os.Handler.handleCallback(Handler.java:605)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.os.Looper.loop(Looper.java:137)
11-02 21:22:07.580: E/AndroidRuntime(15871): at android.app.ActivityThread.main(ActivityThread.java:4511)
11-02 21:22:07.580: E/AndroidRuntime(15871): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 21:22:07.580: E/AndroidRuntime(15871): at java.lang.reflect.Method.invoke(Method.java:511)
11-02 21:22:07.580: E/AndroidRuntime(15871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
11-02 21:22:07.580: E/AndroidRuntime(15871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
11-02 21:22:07.580: E/AndroidRuntime(15871): at dalvik.system.NativeStart.main(Native Method)
Thanks from a head
Nir
It's difficult to tell what's going ong. You're getting a null pointer exception in the trace, which of the source statements is failing?
Related
This question already has answers here:
After Google Play Service update to version 13 I got an error
(8 answers)
Closed 9 years ago.
Yesterday I updated my eclipse. Before I update the eclipse, my application ran correctly but after I updated the eclipse when I run the application,I have an error,
MY LOGCAT
11-02 04:50:32.548: D/AndroidRuntime(2161): Shutting down VM 11-02 04:50:32.548: W/dalvikvm(2161): threadid=1: thread exiting with
uncaught exception (group=0x40a71930) 11-02 04:50:32.609:
E/AndroidRuntime(2161): FATAL EXCEPTION: main 11-02 04:50:32.609:
E/AndroidRuntime(2161): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.vindypratama.tempatwisata/com.vindypratama.tempatwisata.MainMapActivity}:
android.view.InflateException: Binary XML file line #7: Error
inflating class fragment 11-02 04:50:32.609: E/AndroidRuntime(2161):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.app.ActivityThread.access$600(ActivityThread.java:141) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.os.Handler.dispatchMessage(Handler.java:99) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.os.Looper.loop(Looper.java:137) 11-02 04:50:32.609:
E/AndroidRuntime(2161): at
android.app.ActivityThread.main(ActivityThread.java:5041) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
java.lang.reflect.Method.invokeNative(Native Method) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
java.lang.reflect.Method.invoke(Method.java:511) 11-02 04:50:32.609:
E/AndroidRuntime(2161): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
dalvik.system.NativeStart.main(Native Method) 11-02 04:50:32.609:
E/AndroidRuntime(2161): Caused by: android.view.InflateException:
Binary XML file line #7: Error inflating class fragment 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.view.LayoutInflater.inflate(LayoutInflater.java:489) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.app.Activity.setContentView(Activity.java:1881) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
com.vindypratama.tempatwisata.MainMapActivity.onCreate(MainMapActivity.java:25)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.app.Activity.performCreate(Activity.java:5104) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-02 04:50:32.609: E/AndroidRuntime(2161): ... 11 more 11-02
04:50:32.609: E/AndroidRuntime(2161): Caused by:
java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 4030500
but found 0. You must have the following declaration within the
element: 11-02
04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown
Source) 11-02 04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.maps.internal.q.v(Unknown Source) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.maps.internal.q.u(Unknown Source) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.dynamic.a.a(Unknown Source) 11-02 04:50:32.609:
E/AndroidRuntime(2161): at
com.google.android.gms.dynamic.a.onInflate(Unknown Source) 11-02
04:50:32.609: E/AndroidRuntime(2161): at
com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown
Source) 11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
11-02 04:50:32.609: E/AndroidRuntime(2161): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
11-02 04:50:32.609: E/AndroidRuntime(2161): ... 21 more 11-02
04:50:45.858: I/Process(2161): Sending signal. PID: 2161 SIG: 9
My activity.java
package org.lucasr.twowayview;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
public class MainMapActivity extends FragmentActivity
{
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_map);
setupMapIfNeeded();
}
private void setupMapIfNeeded()
{
if(map == null)
{
FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment supportMapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.maps);
map = supportMapFragment.getMap();
if(map != null)
{
setupMap();
}
}
}
private void setupMap()
{
map.setMyLocationEnabled(true);
moveToMyLocation();
}
private void moveToMyLocation()
{
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
if ( location != null)
{
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
}
}
#Override public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_map, menu);
return true;
}
protected void onResume()
{
super.onResume();
int resCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if( resCode != ConnectionResult.SUCCESS)
{
GooglePlayServicesUtil.getErrorDialog(resCode, this, 1);
}
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vindypratama.tempatwisata"
android:versionCode="1"
android:versionName="1.0" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.vindypratama.tempatwisata.permission.MAPS_RECEIVE" />
<permission
android:name="com.vindypratama.tempatwisata.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission><uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDcosD0fQsQcYCEiDDkRxP6ZRACPf-svaw" />
<activity
android:name="com.vindypratama.tempatwisata.MainMapActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application><manifest>
</manifest>
xml file:
<fragment
android:id="#+id/maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
Try to use Project -> Clean. That actually helped me.
EDIT: If that doesn't help, try to relaunch Eclipse after Clean.
you are using a custom class - twowayview. fix you build path. check if you have checked the added jars in your build path. clean the project. delete bin folder.clear/refresh the project. it will work
I am new to Android.
Trying to show a dialog on press of a button like below using DialogFragments
File : Dialog2/LoginDialog.java
package com.kartnet.Dialog2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.LayoutInflater;
import android.widget.Toast;
import android.content.Context;
import android.app.Dialog;
import android.content.DialogInterface;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.util.Log;
public class LoginDialog extends DialogFragment
{
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder ad_builder = new AlertDialog.Builder(getActivity());
//ad_builder.setMessage(R.string.login_dialog);
DialogInterface.OnClickListener ad_listener =
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg1, int id) {
final String tag = "CustomDlg";
Log.d(tag, id + " clicked");
}
};
ad_builder.setTitle(R.string.btn_dialog_custom_title);
LayoutInflater linf = getActivity().getLayoutInflater();
ad_builder.setView(linf.inflate(R.layout.dialog_signin, null));
ad_builder.setNegativeButton("Cancel", ad_listener);
ad_builder.setPositiveButton("Ok", ad_listener);
return ad_builder.create();
}
}
File : Dialog2/Dialog2App.java
package com.kartnet.Dialog2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.LayoutInflater;
import android.widget.Toast;
import android.content.Context;
import android.app.Dialog;
import android.content.DialogInterface;
import android.app.DialogFragment;
import android.app.AlertDialog;
import android.util.Log;
public class Dialog2App extends Activity
{
/* Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void displayDialogCustom(View v)
{
LoginDialog ld = new LoginDialog(); /*<<=== FAILS with runtime exception */
// ld.show(getFragmentManager(), "login_dialog");
} /* displayCustomDialog */
}
Why should it fail at runtime, with no errors during compile time? Also, since both files are declared to be in the same package (com.kartnet.Dialog2), is there anything special I need to get these two java files to be in the application?
Here is what the error displayed
I/ActivityManager( 69): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.kartnet.Dialog2/.Dialog2App } from pid 210
I/ActivityManager( 69): Start proc com.kartnet.Dialog2 for activity com.kartnet.Dialog2/.Dialog2App: pid=1328 uid=10034 gids={1015}
W/dalvikvm( 1328): Unable to resolve superclass of Lcom/kartnet/Dialog2/LoginDialog; (7)
W/dalvikvm( 1328): Link of class 'Lcom/kartnet/Dialog2/LoginDialog;' failed
E/dalvikvm( 1328): Could not find class 'com.kartnet.Dialog2.LoginDialog', referenced from method com.kartnet.Dialog2.Dialog2App.displayDialogCustom
W/dalvikvm( 1328): VFY: unable to resolve new-instance 25 (Lcom/kartnet/Dialog2/LoginDialog;) in Lcom/kartnet/Dialog2/Dialog2App;
D/dalvikvm( 1328): VFY: replacing opcode 0x22 at 0x0000
D/dalvikvm( 1328): VFY: dead code 0x0002-0005 in Lcom/kartnet/Dialog2/Dialog2App;.displayDialogCustom (Landroid/view/View;)V
I/ActivityManager( 69): Displayed com.kartnet.Dialog2/.Dialog2App: +1s956ms
D/dalvikvm( 317): GC_EXPLICIT freed 19K, 55% free 2588K/5703K, external 1625K/2137K, paused 3208ms
D/AndroidRuntime( 1328): Shutting down VM
W/dalvikvm( 1328): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 1328): FATAL EXCEPTION: main
E/AndroidRuntime( 1328): java.lang.IllegalStateException: Could not execute method of the activity
E/AndroidRuntime( 1328): at android.view.View$1.onClick(View.java:2144)
E/AndroidRuntime( 1328): at android.view.View.performClick(View.java:2485)
E/AndroidRuntime( 1328): at android.view.View$PerformClick.run(View.java:9080)
E/AndroidRuntime( 1328): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 1328): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1328): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1328): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 1328): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1328): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1328): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 1328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 1328): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1328): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 1328): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1328): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1328): at android.view.View$1.onClick(View.java:2139)
E/AndroidRuntime( 1328): ... 11 more
E/AndroidRuntime( 1328): Caused by: java.lang.NoClassDefFoundError: com.kartnet.Dialog2.LoginDialog
E/AndroidRuntime( 1328): at com.kartnet.Dialog2.Dialog2App.displayDialogCustom(Dialog2App.java:104)
E/AndroidRuntime( 1328): ... 14 more
Based on the attached log, it appears you're trying to run the code on an older device which does not offer native support to Fragments:
Unable to resolve superclass of Lcom/kartnet/Dialog2/LoginDialog;
Above basically means that android.app.DialogFragment could not be resolved, which will happen on pre-Honeycomb (< Android 3.0 / API level 11) devices. You were probably looking for the backwards compatible Fragment classes that are part of the support library (in the android.support.v4.app.* package).
To migrate your code to the classes in the support libary, you should:
Set up the support library.
Change all android.app.DialogFragment references to android.support.v4.app.DialogFragment (and also any other Fragment classes you may be using).
Change your Activity to a FragmentActivity (also located in the support libary).
Use this dialog manager to display simple dialogs.
public class AlertDialogManager {
/**
* Function to display simple Alert Dialog
* #param context - application context
* #param title - alert dialog title
* #param message - alert message
* #param status - success/failure (used to set icon)
* - pass null if you don't want icon
* */
public void showAlertDialog(Context context, String title, String message,
Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
if(status != null)
// Setting alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
}
}
In your activity you can use this
alert.showAlertDialog(MainActivity.this,"Header","Message", false);
Try this:
Properties->Java Build Path->Order and Export and check Android Private Libraries
You can try to create the dialog before you return it with
Dialog d = ad_builder.create();
return d;
to see if it fail to create the dialog.
DialogFragment are singletons, so you cannot do:
LoginDialog ld = new LoginDialog(); /*<<=== FAILS with runtime exception */
you should use LoginDialog.instantiate(...) method
EDIT: For those struggling with this, checkout this link. Follow it carefully, but it does work! The crucial part is using keytool to generate your SHA1 hash against your debug keystore. Also, don't forget to add one for release too!
I've been trying to setup Google Maps Android API v2 and after setting everything up as said I'm getting this runtime exception ClassNotFound:
01-02 16:29:07.927: E/AndroidRuntime(12508): FATAL EXCEPTION: main
01-02 16:29:07.927: E/AndroidRuntime(12508): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.os.Looper.loop(Looper.java:130)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.main(ActivityThread.java:3701)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.reflect.Method.invoke(Method.java:507)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
01-02 16:29:07.927: E/AndroidRuntime(12508): at dalvik.system.NativeStart.main(Native Method)
01-02 16:29:07.927: E/AndroidRuntime(12508): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.Activity.setContentView(Activity.java:1657)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.example.app.MapActivity.onCreate(MapActivity.java:11)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
01-02 16:29:07.927: E/AndroidRuntime(12508): ... 11 more
01-02 16:29:07.927: E/AndroidRuntime(12508): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.app-1.apk]
01-02 16:29:07.927: E/AndroidRuntime(12508): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-02 16:29:07.927: E/AndroidRuntime(12508): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
01-02 16:29:07.927: E/AndroidRuntime(12508): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-02 16:29:07.927: E/AndroidRuntime(12508): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-02 16:29:07.927: E/AndroidRuntime(12508): ... 20 more
Has anyone ever come across this before?
XML:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
MapActivity:
import android.os.Bundle;
import android.app.Activity;
public class MapActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
}
}
Your Activity needs to extend FragmentActivity from the support library
Try this code working perfect help full to you.
XML
<RelativeLayout 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"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
Java
package com.example.androidmapsv2;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment
= (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
"isGooglePlayServicesAvailable SUCCESS",
Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
}
}
}
Did you run on AVD? if yes try on real devices
I created an Android app which has an FTP connection, however when I start the app it says "unfortunately your app must stopped", and I can't find the problem.
I tried to enter local passive mode however it didn't help me, I also tried to run the app on my phone however it gave me the same message.
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
Button scan;
String contents;
String format;
TextView contentstext;
TextView formattext;
FTPClient ftpclient;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//----------------------FTP-------------
new FtpTask().execute();
//ftpclient.enterLocalPassiveMode();
try {
ftpclient.changeToParentDirectory();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
scan=(Button)findViewById(R.id.scanbutton);
contentstext=(TextView)findViewById(R.id.contentstext);
formattext=(TextView)findViewById(R.id.formattext);
scan.setOnClickListener(this);
}
private class FtpTask extends AsyncTask<Void, Void, FTPClient> {
protected FTPClient doInBackground(Void... args) {
FTPClient ftp = new FTPClient ();
try {
ftp.connect("ftp.drivehq.com");
ftp.login("zule","****");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ftp;
}
protected void onPostExecute(FTPClient result) {
Log.v("FTPTask","FTP connection complete");
ftpclient = result;
}
}
here is the logcat:
09-17 12:11:30.319: E/AndroidRuntime(1113): FATAL EXCEPTION: main
09-17 12:11:30.319: E/AndroidRuntime(1113): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.market/com.example.market.MainActivity}: java.lang.NullPointerException
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.os.Looper.loop(Looper.java:137)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-17 12:11:30.319: E/AndroidRuntime(1113): at java.lang.reflect.Method.invokeNative(Native Method)
09-17 12:11:30.319: E/AndroidRuntime(1113): at java.lang.reflect.Method.invoke(Method.java:511)
09-17 12:11:30.319: E/AndroidRuntime(1113): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-17 12:11:30.319: E/AndroidRuntime(1113): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-17 12:11:30.319: E/AndroidRuntime(1113): at dalvik.system.NativeStart.main(Native Method)
09-17 12:11:30.319: E/AndroidRuntime(1113): Caused by: java.lang.NullPointerException
09-17 12:11:30.319: E/AndroidRuntime(1113): at com.example.market.MainActivity.onCreate(MainActivity.java:32)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.Activity.performCreate(Activity.java:4465)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-17 12:11:30.319: E/AndroidRuntime(1113): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-17 12:11:30.319: E/AndroidRuntime(1113): ... 11 more
Look at the stack trace. It says you have a NullPointerException on line 32.
If I counted right, that's this line:
ftpclient.changeToParentDirectory();
Notice that your class member ftpClient is not instantiated; so it's still null when you try to call changeToParentDirectory() on it.
Adding ftpClient = new FtpClient( ... ) somewhere before this call should solve your problem. Add the correct parameters for the dots.
I have this code for an expandable list, I want to have a checkbox in the childgroups of the list view, and check if one of the checkboxes is checked.
The problem is that when I check if the checkbox is checked I get a NULL Pointer Exception.
Can you please tell me whats wrong?
here's my code - I've edited the code to inflate a view of the child_row.xml that holds that checkbox but I still get that null pointer, what am I doing wrong?!?!
package send.Shift;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
public class Shifts extends ExpandableListActivity implements
OnCheckedChangeListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.list);
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
this, createGroupList(), R.layout.group_row,
new String[] { "Group Item" }, new int[] { R.id.row_name },
createChildList(), R.layout.child_row,
new String[] { "Sub Item" }, new int[] { R.id.grp_child });
getExpandableListView().setGroupIndicator(
getResources().getDrawable(R.drawable.expander_group));
ExpandableListView EX = (ExpandableListView) findViewById(android.R.id.list);
EX.setAdapter(expListAdapter);
final CheckBox childBox = (CheckBox) findViewById(R.id.childBOX);
final TextView choosenGroup = (TextView) findViewById(R.id.choosen);
LayoutInflater inflater = LayoutInflater.from(Shifts.this);
View view2 = inflater.inflate(R.layout.child_row, null);
childBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if(childBox.isChecked() == true){
choosenGroup.setText("Shift Set");
}
}
});
}
Here is some of the Logcat log:
12-23 07:38:00.644: W/dalvikvm(880): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-23 07:38:00.654: E/AndroidRuntime(880): FATAL EXCEPTION: main
12-23 07:38:00.654: E/AndroidRuntime(880): java.lang.RuntimeException: Unable to start activity ComponentInfo{send.Shift/send.Shift.Shifts}: java.lang.NullPointerException
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.os.Looper.loop(Looper.java:123)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-23 07:38:00.654: E/AndroidRuntime(880): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 07:38:00.654: E/AndroidRuntime(880): at java.lang.reflect.Method.invoke(Method.java:507)
12-23 07:38:00.654: E/AndroidRuntime(880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-23 07:38:00.654: E/AndroidRuntime(880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-23 07:38:00.654: E/AndroidRuntime(880): at dalvik.system.NativeStart.main(Native Method)
12-23 07:38:00.654: E/AndroidRuntime(880): Caused by: java.lang.NullPointerException
12-23 07:38:00.654: E/AndroidRuntime(880): at send.Shift.Shifts.onCreate(Shifts.java:41)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-23 07:38:00.654: E/AndroidRuntime(880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-23 07:38:00.654: E/AndroidRuntime(880): ... 11 more
If you get a nullpointer on a certain line, something on that line is null. If it is the if(childBox.isChecked() line, probably childBox is null. Hard to say without the stack, but most probable cause is the line where you retrieve that checkbox.
final CheckBox childBox = (CheckBox) findViewById(R.id.childBOX);
Might be returning null, and this could be for several reasons. It could be your id is childBox instead of childBOX. Or that it is not in R.layout.list.
The best thing you can do is start debugging. What line is the error. Find the object that is null. Find out why it is null and if that is expected or not.
Instead of checking the childBox.isChecked() you can use the isChecked value. So your code would look like this:
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked == true){
choosenGroup.setText("Shift Set");
}
}
Check your layout list.xml I think this layout may is missing android:id="#+id/childBOX" for Check Box or android:id="#+id/choosen" for TextView
Check the folowin sample
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/childBOX"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/choosen"/>