- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中单击图像按钮时,我总是收到消息:“不幸的是,myapp已停止”。问题是什么???
这是我的代码。单击图像按钮将调用showImageDialog方法:
public class ReminderEditActivity extends Activity {
//
// Private instance variables
//
private Button mDateButton;
private Calendar mCalendar;
private Button mTimeButton;
private EditText mTitleText;
private EditText mBodyText;
private Button mConfirmButton;
private RemindersDbAdapter mDbHelper;
private ImageAdapter mImageHelper;
private Long mRowId;
private Long mImageRowId;
private ImageButton mImageButton;
private Uri mImageCaptureUri;
public String imageFilePath;
//
// Private constants
//
private static final int DATE_PICKER_DIALOG = 0;
private static final int TIME_PICKER_DIALOG = 1;
private static final String DATE_FORMAT = "dd-MM-yyyy";
private static final String TIME_FORMAT = "kk:mm";
public static final String DATE_TIME_FORMAT = "dd-MM-yyyy kk:mm:ss";
private static final int PICK_FROM_CAMERA = 1;
private static final int PICK_FROM_FILE = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Instantiate mDbHelper and mImageHelper
mDbHelper = new RemindersDbAdapter(this);
mImageHelper = new ImageAdapter(this);
setContentView(R.layout.reminder_edit);
//
// Instantiate instance variables
//
mTimeButton = (Button)findViewById(R.id.reminder_time);
mCalendar = Calendar.getInstance();
mDateButton = (Button)findViewById(R.id.reminder_date);
mConfirmButton = (Button)findViewById(R.id.confirm);
mTitleText = (EditText)findViewById(R.id.title);
mBodyText = (EditText)findViewById(R.id.body);
mImageButton =(ImageButton)findViewById(R.id.image);
//Checks whether mRowId contains any values.
mRowId = savedInstanceState != null ? savedInstanceState.getLong(RemindersDbAdapter.KEY_ROWID) : null;
mImageRowId = savedInstanceState != null ? savedInstanceState.getLong(ImageAdapter.KEY_ROWID) : null;
registerButtonListenerandSetDefaultText();
}
//
// Sets the row id from the intent. If mRowId is null its content is null.
//
private void setRowIdFromIntent() {
if(mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(RemindersDbAdapter.KEY_ROWID) : null;
}
}
//
// Executed on pause.
//
@Override
protected void onPause() {
super.onPause();
mDbHelper.close();
mImageHelper.close();
}
//
// Executed on resume
//
@Override
protected void onResume() {
super.onResume();
mDbHelper.open();
mImageHelper.open();
setRowIdFromIntent();
populateFields();
populateImageField();
}
//
// Register the Date, Time and Save Button and set the default text
//
private void registerButtonListenerandSetDefaultText() {
mDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_PICKER_DIALOG);
}
});
mTimeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(TIME_PICKER_DIALOG);
}
});
mConfirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
saveState();
setResult(RESULT_OK);
Toast.makeText(ReminderEditActivity.this, getString(R.string.task_saved_message), Toast.LENGTH_SHORT).show();
finish();
}
});
mImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showImageDialog();
}
});
updateDateButtonText();
updateTimeButtonText();
}
private void showImageDialog() {
final String [] items = new String [] {"From Camera", "From SD Card"};
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.select_dialog_item,items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Image");
builder.setAdapter( adapter, new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int item ) {
if (item == 0) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
mImageCaptureUri = Uri.fromFile(file);
try {
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (Exception e) {
e.printStackTrace();
}
dialog.cancel();
} else {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}
}
} );
final AlertDialog dialog = builder.create();
dialog.show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_FROM_FILE && data != null && data.getData() != null) {
Uri uri = data.getData();
if(uri != null) {
Cursor cursor = getContentResolver().query(uri, new String[] {
android.provider.MediaStore.Images.ImageColumns.DATA},
null, null, null);
cursor.moveToFirst();
String imageFilePath = cursor.getString(0);
cursor.close();
if(imageFilePath != null) {
// Do whatever you want like decode it into a Bitmap
Bitmap bitmap = BitmapFactory.decodeFile(imageFilePath);
mImageButton.setImageBitmap(bitmap);
// Or.. store it somewhere in your local db
}
}
}
}
//
// If mRowId is not null (it contains value and we want to edit the task)
// this method is called.
//
private void populateFields() {
if (mRowId != null) {
Cursor reminder = mDbHelper.fetchReminder(mRowId);
startManagingCursor(reminder);
mTitleText.setText(reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_TITLE)));
mBodyText.setText(reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_BODY)));
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
Date date = null;
try {
String dateString = reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_DATE_TIME));
date = dateTimeFormat.parse(dateString);
mCalendar.setTime(date);
} catch (ParseException e) {
Log.e("ReminderEditActivity", e.getMessage(), e);
}
}
updateDateButtonText();
updateTimeButtonText();
}
private void populateImageField() {
if (mImageRowId != null) {
Cursor reminderImage = mImageHelper.fetchReminder(mImageRowId);
startManagingCursor(reminderImage);
String imagePath = reminderImage.getString(reminderImage.getColumnIndexOrThrow(ImageAdapter.KEY_IMAGE));
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
mImageButton.setImageBitmap(bitmap);
}
}
//
// Saves the state so that it can be restored.
//
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(RemindersDbAdapter.KEY_ROWID, mRowId);
}
//
// Saves the content by communicating with the RemindersDbAdapter.
//
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
String reminderDateTime = dateTimeFormat.format(mCalendar.getTime());
// Creates a new reminder if the value is null.
if (mRowId == null) {
long id = mDbHelper.createReminder(title, body, reminderDateTime);
if (id > 0) {
mRowId = id;
}
// Updates the reminder if the content is not null.
} else {
mDbHelper.updateReminder(mRowId, title, body, reminderDateTime);
}
}
//
// Opens up an alert dialog box and asks the user if he wants to discard his task.
//
@Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(ReminderEditActivity.this);
builder.setMessage("Are you sure you want to discard your task?");
builder.setTitle("Are you sure?");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Intent j = new Intent(((Dialog)dialog).getContext(), ReminderListActivity.class);
startActivity(j);
return;
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.create().show();
}
//
// When creating a dialog box, it either shows up a date or time picker.
//
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_PICKER_DIALOG:
return showDatePicker();
case TIME_PICKER_DIALOG:
return showTimePicker();
}
return super.onCreateDialog(id);
}
//
// Creates the date picker dialog box.
//
private DatePickerDialog showDatePicker() {
DatePickerDialog datePicker = new DatePickerDialog(ReminderEditActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mCalendar.set(Calendar.YEAR, year);
mCalendar.set(Calendar.MONTH, monthOfYear);
mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateDateButtonText();
}
}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
return datePicker;
}
//
// Creates the time picker dialog box.
//
private TimePickerDialog showTimePicker() {
TimePickerDialog timePicker = new TimePickerDialog(ReminderEditActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
mCalendar.set(Calendar.MINUTE, minute);
updateTimeButtonText();
}
}, mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE), true);
return timePicker;
}
//
// Updates the Date Button text.
//
private void updateDateButtonText() {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
String dateForButton = dateFormat.format(mCalendar.getTime());
mDateButton.setText(dateForButton);
}
//
// Updates the Time Button text.
//
private void updateTimeButtonText() {
SimpleDateFormat timeFormat = new SimpleDateFormat(TIME_FORMAT);
String timeForButton = timeFormat.format(mCalendar.getTime());
mTimeButton.setText(timeForButton);
}
05-30 22:09:06.726: E/AndroidRuntime(628): FATAL EXCEPTION: main
05-30 22:09:06.726: E/AndroidRuntime(628): java.lang.RuntimeException: Unable to pause activity {com.ndroidstudios.android.taskreminder/com.ndroidstudios.android.taskreminder.ReminderEditActivity}: java.lang.NullPointerException
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2706)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2662)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2640)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread.access$800(ActivityThread.java:123)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1154)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.os.Looper.loop(Looper.java:137)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-30 22:09:06.726: E/AndroidRuntime(628): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 22:09:06.726: E/AndroidRuntime(628): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 22:09:06.726: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 22:09:06.726: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 22:09:06.726: E/AndroidRuntime(628): at dalvik.system.NativeStart.main(Native Method)
05-30 22:09:06.726: E/AndroidRuntime(628): Caused by: java.lang.NullPointerException
05-30 22:09:06.726: E/AndroidRuntime(628): at com.ndroidstudios.android.taskreminder.ReminderEditActivity.onSaveInstanceState(ReminderEditActivity.java:345)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.Activity.performSaveInstanceState(Activity.java:1113)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1185)
05-30 22:09:06.726: E/AndroidRuntime(628): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2688)
05-30 22:09:06.726: E/AndroidRuntime(628): ... 12 more
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ndroidstudios.android.taskreminder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ReminderListActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ReminderEditActivity"
android:label="@string/app_name" />
<activity
android:name=".ImageAdapter"
android:label="@string/app_name" />
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
最佳答案
第345行的ReminderEditActivity具有空对象。我不确定代码中的哪一行会导致没有行号
关于android - 为什么我的Android应用程序中出现 “unfortunately myapp has stopped”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10823613/
抱歉,如果不解释整个情况,我想不出更具描述性的标题。 我正在使用 IIS7 和 Tomcat7。我使用 GWT 创建了一个 Web 应用程序,将其打包成一个 war 文件并将其部署在 Tomcat 上
我知道有几个主题与此有关,但几天后我无法定位并解决这个问题。到目前为止我已经完成的步骤: 已安装tomcat 8.5.8 更改了/opt/tomcat/conf/server.xml 中的以下行
(顺便说一下,我正在使用 WebSphere 7) 我有一个带有基本身份验证和配置的安全约束的 Java 网络应用程序(如下所示)。 当我在 http://localhost:9080/myapp/
在 Windows 批处理文件或命令提示符中,调用 start mspaint 和 mspaint 之间有什么区别?它们似乎在做完全相同的事情。 另一个例子,所有 4 个案例似乎都在做同样的事情。如果
在构建我的 C# .NET 项目时,“MyApp.vshost.exe”文件与 Visual Studio 2010 下的“MyApp.exe”一起放置在发布站中。分发“MyApp.exe”时,我应该
我正在使用 Firebase Auth signInWithPopup(),这绝对很棒。但最初配置时,弹出窗口显示: Choose an account to continue to myApp-12
我将 war 文件放在共享驱动器上。我在我的 tomcat ...\conf\Catalina\localhost\myapp.xml 中设置了 docBase,如下所示: 当共享驱动器启动时,tom
身份验证后,asp.net 将我的用户重定向到 .../myapp/default.aspx 而不是 .../myapp/ 有什么办法可以解决这个问题吗?我认为在 url 上包含额外的 default
我知道这听起来可能很愚蠢,但我只是想知道如果我在我的已安装应用程序列表中输入“myapp”而不是“myapp.apps.myappConfig”有什么区别。它与模型有关还是什么? 问候 最佳答案 如果
来自 vshost(在 VS 版本中运行) array pure 00:00:02.9634819 1200000000 Basic: 00:00:04.1682663 来自独立程序(编译版本)
我有错误: BadRequestError: app "dev~myapp" cannot access app "s~myapp"'s data 这很相似,但是 the opposite way a
我已经为我的软件制作了安装程序(使用Inno Setup),最终安装在 C:\Program Files (x86)\MyApp\myapp.exe 像往常一样在 Windows 平台上运行,并且运行
我正在尝试运行 Ratchet 应用程序演示,但我无法执行该文件 这是我的文件结构 /var/www/src/MyApp/ /var/www/src/MyApp/chat.php /var/www/s
这是我的Flutter中凸起按钮的代码,如果我更换 void main()=> runApp(MaterialApp(home:MyApp())); 与 void main()=> runApp(My
就在几天前,我成功将 Ionic 应用程序上传到 Apple Store,而在这一天,我收到了验证警告: The app references non-public selectors in Payl
使用 Morph Labs 的 Appspace 部署站点意味着无法自动将“myapp.com”重定向到“www.myapp.com”(并且无法访问 .htacess)。 是否有 rails 内方式来
当我使用 Java 时,我需要输入类似java -?的命令如果用户在最后输入-?,为什么应用程序知道这个来回复输出?请告诉我识别-?的c代码 最佳答案 它们作为参数传递给 main(): #inclu
我试过使用 Environment.CommandLine 来检查可执行文件,但这没有用,它总是显示 dll 文件。关于如何知道 myapp.exe 文件是否用于运行应用程序或者是否使用 dotnet
我有一个问题,大约 2 天我无法解决。我分析了几乎所有关于这个错误的问题,但我无法处理它。 这是我的树: MyAppRoot -MyApp -libs -jar4.jar
最近我在 Linux Centos 上遇到 Apache Tomcat 6.0.35 的问题。我收到错误 - java.lang.UnsupportedClassVersionError: myApp
我是一名优秀的程序员,十分优秀!