I tried to play a file in ListView with mediaPlayer class.
Like this:
public void initializeViews() {
Intent intent = getIntent();
String fName = intent.getStringExtra("fileName");
fileName = (TextView) findViewById(R.id.fileName);
duration = (TextView) findViewById(R.id.songDuration);
seekbar = (SeekBar) findViewById(R.id.seekBar);
playBtn = (ImageButton) findViewById(R.id.media_play);
try {
mediaPlayer = new android.media.MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(fName);
mediaPlayer.prepare();
}
catch (IOException e) {
e.printStackTrace();
}
fileName.setText(fName.substring(fName.lastIndexOf("/") + 1));
finalTime = mediaPlayer.getDuration();
seekbar.setOnSeekBarChangeListener(mOnSeek);
seekbar.setMax((int) finalTime);
seekbar.setClickable(true);
mediaPlayer.start();
timeElapsed = mediaPlayer.getCurrentPosition();
seekbar.setProgress((int) timeElapsed);
durationHandler.postDelayed(updateSeekBarTime, 200);
}
I search on the internet, and the most question is check the path to file, but the fName got the full path to a file. But I don't know it shows exception:
java.io.IOException: Prepare failed.: status=0x1
All log when application occurs exception:
E/MediaPlayer: error (1, -2147483648)
W/System.err: java.io.IOException: Prepare failed.: status=0x1
W/System.err: at android.media.MediaPlayer.prepare(Native Method)
W/System.err: at kr.co.composer.callrecord.media.AudioPlayer.initializeViews(AudioPlayer.java:56)
W/System.err: at kr.co.composer.callrecord.media.AudioPlayer.onCreate(AudioPlayer.java:42)
W/System.err: at android.app.Activity.performCreate(Activity.java:5231)
W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
W/System.err: at android.app.ActivityThread.access$800(ActivityThread.java:135)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:136)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5001)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
E/MediaPlayer: Attempt to call getDuration without a valid mediaplayer
E/MediaPlayer: error (-38, 0)
E/MediaPlayer: start called in state 0
E/MediaPlayer: error (-38, 0)
E/MediaPlayer: Error (-38,0)
E/MediaPlayer: Error (-38,0)
W/EGL_genymotion: eglSurfaceAttrib not implemented
stop called in state 0
error (-38, 0)
stop called in state 0
error (-38, 0)
Error (-38,0)
Error (-38,0)
stop called in state 0
error (-38, 0)
Error (-38,0)
pause called in state 0
error (-38, 0)
Possible caused by reading permission. Fix by inserting the permission in manifest file:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Related
I am running an app to test whether I can use Microsoft Translator API on a phone running Android API 19. However, when I press a button to get translated text, instead of translating the text "This is my dog" to French, Microsoft Translator API returns "".
UPDATE: Logcat is returning this:
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: java.lang.Exception: [microsoft-translator-api] Error retrieving translation : Permission denied (missing INTERNET permission?)
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:202)
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: at com.memetix.mst.translate.Translate.execute(Translate.java:61)
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: at com.example.inspiron.translat.MainActivity$1$1MyAsyncTask.doInBackground(MainActivity.java:45)
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: at com.example.inspiron.translat.MainActivity$1$1MyAsyncTask.doInBackground(MainActivity.java:38)
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-07 07:13:52.148 28001-28250/com.example.inspiron.translat W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-07 07:13:52.158 28001-28250/com.example.inspiron.translat W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-07 07:13:52.158 28001-28250/com.example.inspiron.translat W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-07 07:13:52.158 28001-28250/com.example.inspiron.translat W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at java.lang.Thread.run(Thread.java:841)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:214)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:390)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:343)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:289)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
02-07 07:13:52.168 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:254)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at com.memetix.mst.MicrosoftTranslatorAPI.getToken(MicrosoftTranslatorAPI.java:133)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:160)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: ... 9 more
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at libcore.io.Posix.getaddrinfo(Native Method)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: ... 24 more
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
02-07 07:13:52.178 28001-28250/com.example.inspiron.translat W/System.err: ... 27 more
02-07 07:15:59.518 29374-29374/com.example.inspiron.translat W/dalvikvm: VFY: unable to resolve virtual method 442: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
02-07 07:15:59.518 29374-29374/com.example.inspiron.translat W/dalvikvm: VFY: unable to resolve virtual method 231: Landroid/app/Activity;.stopLockTask ()V
02-07 07:15:59.518 29374-29374/com.example.inspiron.translat E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.inspiron.translat.MainActivity.access$super
02-07 07:15:59.518 29374-29374/com.example.inspiron.translat W/dalvikvm: VFY: unable to resolve check-cast 227 (Landroid/os/PersistableBundle;) in Lcom/example/inspiron/translat/MainActivity;
02-07 07:15:59.518 29374-29374/com.example.inspiron.translat W/dalvikvm: VFY: unable to resolve virtual method 424:
My code is:
public class MainActivity extends AppCompatActivity {
TextView subject;
Button submit;
TextView result;
String stayalive;
String translatedText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
subject = (TextView) findViewById(R.id.textView);
submit = (Button) findViewById(R.id.button);
result = (TextView) findViewById(R.id.textView2);
Translate.setClientId("CLIENT ID");
Translate.setClientSecret("CLIENT SECRET");
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
class MyAsyncTask extends AsyncTask<DownloadManager.Request, Void, String> {
protected String doInBackground() {
try {
translatedText = Translate.execute("This is my dog", Language.AUTO_DETECT, Language.FRENCH);
return "";
} catch (Exception e) {
e.printStackTrace();
return "";
// I can't do a void
}
}
#Override
protected String doInBackground(DownloadManager.Request... params) {
return null;
}
#Override
protected void onPostExecute(String s) {
if (subject != null){
subject.setText(translatedText);
Context context = getApplicationContext();
CharSequence text = translatedText;
// the Toast didn't have any text in it
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
} else {
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
}
new MyAsyncTask().execute();
}
});
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.inspiron.translat">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<uses-permission android:name="android.permission.INTERNET"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Is the error because of my code or is it because of Microsoft Translator API itself? (I am using microsoft-translator-java-api-0.6.2-jar-with-dependencies.jar from https://code.google.com/archive/p/microsoft-translator-java-api/downloads.)
UPDATE 2: I got the answer from Permission denied (missing INTERNET permission?): But permission is given. Apparently I was supposed to put the <uses-permission> tags above application.
why you need two doInBackground call? Remove one and try
I have an expandable list view however when I expand it and click on the child I get an error that reads
FATAL EXCEPTION: main
Process: com.claritech.simsentinelmobile, PID: 22606
java.lang.ClassCastException: android.widget.ExpandableListConnector
cannot be cast to com.xera.deviceinsight.home.ExpandableListAdapter
This is the line that is throwing the error
ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();
and this is the entire method I am trying to use an adapter to retrieve an object(details about the clicked child from server using retrofit)
private void load(View view)
{
expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
prepareListData();
listAdapter = new ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
System.err.println("child clicked");
Toast.makeText(getActivity(), "child clicked", Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new ItemClickedEvent(SensorInformationChildFragment.TAB_CALL));
//ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();
ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();
OrganisationDeviceSensorsResult d = (OrganisationDeviceSensorsResult) adapter.getChild(groupPosition, childPosition);
d.SensorID = d.SensorID;
OrganisationDeviceSensorsResult deviceSensor = (OrganisationDeviceSensorsResult) adapter.getChild(groupPosition , childPosition);
Object contact = adapter.getChild(groupPosition , childPosition);
// OrganisationDeviceSensorsResult contact = listDataChild.get(groupPosition).getContacts().get(childPosition);
//sensorID = deviceSensor.SensorID;
//sensorID = contact.equals()
ReportingGroup.get(childPosition);
return true;
}
});
}
This is the log
01-11 11:42:30.328 22606-22606/com.claritech.simsentinelmobile D/dalvikvm: threadid=1: detach (group=0x41816ce0)
01-11 11:42:30.328 22606-22606/com.claritech.simsentinelmobile W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41816ce0)
01-11 11:42:30.328 22606-22606/com.claritech.simsentinelmobile W/dalvikvm: threadid=1: uncaught exception occurred
01-11 11:42:30.329 22606-22606/com.claritech.simsentinelmobile W/System.err: java.lang.ClassCastException: android.widget.ExpandableListConnector cannot be cast to com.xera.deviceinsight.home.ExpandableListAdapter
01-11 11:42:30.329 22606-22606/com.claritech.simsentinelmobile W/System.err: at com.xera.deviceinsight.home.CostCentreListFragment$1.onChildClick(CostCentreListFragment.java:88)
01-11 11:42:30.329 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:712)
01-11 11:42:30.330 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:651)
01-11 11:42:30.330 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
01-11 11:42:30.330 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.widget.AbsListView$3.run(AbsListView.java:3865)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.os.Handler.handleCallback(Handler.java:808)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.os.Handler.dispatchMessage(Handler.java:103)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.os.Looper.loop(Looper.java:193)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5299)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
01-11 11:42:30.333 22606-22606/com.claritech.simsentinelmobile W/System.err: at dalvik.system.NativeStart.main(Native Method)
01-11 11:42:30.333 22606-22606/com.claritech.simsentinelmobile W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
01-11 11:42:30.335 22606-22606/com.claritech.simsentinelmobile E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.claritech.simsentinelmobile, PID: 22606
java.lang.ClassCastException: android.widget.ExpandableListConnector cannot be cast to com.xera.deviceinsight.home.ExpandableListAdapter
at com.xera.deviceinsight.home.CostCentreListFragment$1.onChildClick(CostCentreListFragment.java:88)
at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:712)
at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:651)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
at android.widget.AbsListView$3.run(AbsListView.java:3865)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
Try using fully qualified class name in the following statement, i.e. -
listAdapter = new com.xera.deviceinsight.home.ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild);
I have button which function is to take screenshot and share it to Facebook. when i try it in my Samsung with JellyBean OS device its working perfectly, but when i try it to BlueStack with JellyBean OS and CheeryMobile with Lollipop OS things are not working, i check the Logcat and i see some error.
my code
onClick of Button call takeScreenshot();
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
sharePhotoToFacebook(imageFile);
} catch (Throwable
e.printStackTrace();
}
}
private void sharePhotoToFacebook(File imageFile){
Uri imageUri = Uri.fromFile(imageFile);
try {
image = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
} catch (IOException e) {
e.printStackTrace();
}
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
List<String> permissionNeeds = Arrays.asList("publish_actions");
//this loginManager helps you eliminate adding a LoginButton to your UI
loginManager = LoginManager.getInstance();
loginManager.logInWithPublishPermissions(this, permissionNeeds);
loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
try{
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setCaption(scoreFinal)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
ShareApi.share(content, null);
final Dialog dialog = new Dialog(ActivityShare.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sucess_shared);
dialog.show();
Button btnOk = (Button) dialog.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
}catch (Exception e){
Log.e("Error on share", String.valueOf(e));
}
}
#Override
public void onCancel() {
Log.w("OnCancel", "Canceled by user");
// System.out.println("onCancel");
}
#Override
public void onError(FacebookException exception) {
final Dialog dialog = new Dialog(ActivityShare.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sucess_shared);
TextView title = (TextView)dialog.findViewById(R.id.titleSuccess);
TextView desc = (TextView)dialog.findViewById(R.id.descriptionHere);
title.setText("Unsuccessfull");
desc.setText("Something's wrong, Please check your internet connection and try again.");
dialog.show();
Button btnOk = (Button) dialog.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
Log.e("OnError", String.valueOf(exception));
// System.out.println("onError");
}
});
}
LogCat Error
01-07 23:34:36.767 2024-2024/com.sample.app W/System.err: java.io.FileNotFoundException: /mnt/sdcard/Thu Jan 07 23:34:36 SGT 2016.jpg: open failed: EINVAL (Invalid argument)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at libcore.io.IoBridge.open(IoBridge.java:406)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at com.sample.app.ActivityShare.takeScreenshot(ActivityShare.java:225)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at com.sample.app.ActivityShare.access$000(ActivityShare.java:42)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at com.sample.app.ActivityShare$1.onClick(ActivityShare.java:103)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at android.view.View.performClick(View.java:3511)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at android.view.View$PerformClick.run(View.java:14105)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at android.os.Handler.handleCallback(Handler.java:605)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at android.os.Looper.loop(Looper.java:137)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:4424)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at java.lang.reflect.Method.invoke(Method.java:511)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at dalvik.system.NativeStart.main(Native Method)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: Caused by: libcore.io.ErrnoException: open failed: EINVAL (Invalid argument)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at libcore.io.Posix.open(Native Method)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: at libcore.io.IoBridge.open(IoBridge.java:390)
01-07 23:34:36.787 2024-2024/com.sample.app W/System.err: ... 16 more
i have no idea about the problem.
Please help me. Thank you!!!
This is my update query,
ContentValues value = new ContentValues();
value.put(DBhelper.Amount, txtBudget.getText().toString());
db = helper.getWritableDatabase();
db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv,null);
db.close();
fetchData2();
Toast.makeText(this, "Update Successfully", Toast.LENGTH_LONG).show();
clearfield();
when click the button to update,it's giving fatal exception error.
value_in_tv this is the value I got from another class
Bundle data_from_list= getIntent().getExtras();
value_in_tv= data_from_list.getString("passed data key");
txr.setText(value_in_tv);
Error:
10-18 20:45:57.812 18632-18632/com.example.username.weddingplanning
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: unrecognized token: "'suba" (code 1): , while compiling: UPDATE Category SET amount=?
WHERE description='suba
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1669)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1620)
at com.example.username.weddingplanning.addbudget.checkIfRowPresent(addbudget.java:134)
at com.example.username.weddingplanning.addbudget.onClick(addbudget.java:114)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
You forgot the closing ' in the where clause:
db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv + "'",null)
I know a bunch of people have asked this same thing but I just don't know what's going on. I'm trying to make a calculator in Eclipse, but I keep getting a list of errors.
There are no errors in the file that the program notices, although there is an error in the layout.xml but it hasn't caused a problem before so that shouldn't cause a problem.
07-30 08:19:50.470: D/AndroidRuntime(2071): Shutting down VM
07-30 08:19:50.470: W/dalvikvm(2071): threadid=1: thread exiting with uncaught
exception (group=0x40a421f8)
07-30 08:19:50.480: E/AndroidRuntime(2071): FATAL EXCEPTION: main
07-30 08:19:50.480: E/AndroidRuntime(2071): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.example.se.miun.chris.calculator/com.example.se.miun.chris.
calculator.MainActivity}: java.lang.NullPointerException
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.ActivityThread.access$600(ActivityThread.java:123)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.os.Looper.loop(Looper.java:137)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.ActivityThread.main(ActivityThread.java:4424)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
java.lang.reflect.Method.invokeNative(Native Method)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
java.lang.reflect.Method.invoke(Method.java:511)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
dalvik.system.NativeStart.main(Native Method)
07-30 08:19:50.480: E/AndroidRuntime(2071): Caused by: java.lang.NullPointerException
07-30 08:19:50.480: E/AndroidRuntime(2071): at
com.example.se.miun.chris.calculator.MainActivity.onCreate(MainActivity.java:60)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.Activity.performCreate(Activity.java:4465)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-30 08:19:50.480: E/AndroidRuntime(2071): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-30 08:19:50.480: E/AndroidRuntime(2071): ... 11 more
This is my coding. It doesn't really do anything yet, but I wanted to just run it to see if it encountered any errors. This is the mainActivity.java file.
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
Button Seven;
Button Eight;
Button Nine;
Button Four;
Button Five;
Button Six;
Button One;
Button Two;
Button Three;
Button Zero;
Button Point;
Button Negative;
TextView TextBox;
int x;
int y;
String z;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Seven = (Button)findViewById(R.id.NumberSeven);
Seven.setOnClickListener(this);
Eight = (Button)findViewById(R.id.NumberEight);
Eight.setOnClickListener(this);
Nine = (Button)findViewById(R.id.NumberNine);
Nine.setOnClickListener(this);
Four = (Button)findViewById(R.id.NumberFour);
Four.setOnClickListener(this);
Five = (Button)findViewById(R.id.NumberFive);
Five.setOnClickListener(this);
Six = (Button)findViewById(R.id.NumberSix);
Six.setOnClickListener(this);
One = (Button)findViewById(R.id.NumberOne);
One.setOnClickListener(this);
Two = (Button)findViewById(R.id.NumberTwo);
Two.setOnClickListener(this);
Three = (Button)findViewById(R.id.NumberThree);
Three.setOnClickListener(this);
Zero = (Button)findViewById(R.id.NumberZero);
Zero.setOnClickListener(this);
Point = (Button)findViewById(R.id.Point);
Point.setOnClickListener(this);
Negative = (Button)findViewById(R.id.NNegative);
Negative.setOnClickListener(this);
TextBox = (TextView)findViewById(R.id.Screen);
x = (Integer) null;
y = (Integer) null;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View One) {
if(z == null){
x = 1;
TextBox.setText(x);
TextBox.setText("diggity");
}
else if(z != null) {
y = 1;
TextBox.setText(x);
TextBox.setText(z);
TextBox.setText(y);
}
}
}
line 60: x = (Integer) null;
This line will compile to this bytecode (disassembled by javap):
aconst_null
checkcast #2; //class java/lang/Integer
invokevirtual #3; //Method java/lang/Integer.intValue:()I
Third line will cause a NullPointerException becouse Integer object is actually your null constant :)
Primitive data types (int, long etc.) is the only non-object types in Java. null is used to show that the current variable (Object variable) is not backed by the actual object (no memory was allocated). For primitive types memory allocates immediately so they cant have this null state.
So you should check for "if(x == 0)" or define it as Integer.
P.S. And don't cast null to anything :)
It's like this
you're not getting much errors because the application can't launch. it cannot launch because it's onCreate() cannot finish.
onCreate() cannot finish because of a nullPointerException.
you cast null into integer twice, instead of simply instantiating a new integer which will default to 0. once you get rid of that, it should work.
see?
E/AndroidRuntime(2071): Caused by: java.lang.NullPointerException
E/AndroidRuntime(2071): at
MainActivity.onCreate(MainActivity.java:60)
and i bet that this is line 60
x = (Integer) null;
so change it to
x = new Integer();