我的Android应用程序的一段代码遇到了一些麻烦.我NullPointerException在尝试设置ImageView对象的背景时不断得到.
这是代码:
public View getView(int position, View view, ViewGroup parent) {
ImageView imageView;
if (view == null) {
imageView = new ImageView(mContext);
} else {
imageView = (ImageView) view;
}
imageView.setTag(position);
return imageView;
}
private OnItemClickListener itemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
ImageView imageView;
//Variable i, here, is from a for loop.
imageView = (ImageView)v.findViewWithTag(i);
//I get a NullPointerException at the next line, "Log.d"
Log.d("View …Run Code Online (Sandbox Code Playgroud) 我想添加 PreferenceFragment一个FragmentPagerAdapter.
我的课程延伸FragmentActivity,我尝试过FragmentTransaction,如下所示,以及尝试添加到容器,似乎无法得到任何工作.没有错误被抛出,实际上没有任何反应.
主要活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中:
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
</android.support.v4.view.ViewPager>
Run Code Online (Sandbox Code Playgroud)
我的选项菜单选择:
android.app.FragmentManager fm;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
JJSettings settings = new JJSettings();
fm = getFragmentManager();
FragmentTransaction fragTrans = fm.beginTransaction();
// I also tried `replace()` here as well. Same 'nothing happens' result.
fragTrans.add(settings, …Run Code Online (Sandbox Code Playgroud) 我的应用程序有点问题.我刚刚实现了捏缩放,但是当我捏缩放时,图像不会在2点的中心缩放,如下图所示.图像1是我的手指在捏之前的位置,图像2是显示它没有像我应该的那样在我的手指中心缩放.
图1与图2:

这是我的代码:
package com.jpiionefourone.guitarimage;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
public class MultiTouchView extends View {
private Drawable mIcon;
private float mPosX;
private float mPosY;
private float mLastTouchX;
private float mLastTouchY;
private static final int INVALID_POINTER_ID = -1;
// The ‘active pointer’ is the one currently moving our object.
private int mActivePointerId = INVALID_POINTER_ID;
private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;
public MultiTouchView(Context context) {
this(context, null, 0);
}
public …Run Code Online (Sandbox Code Playgroud) 有没有办法点击子菜单中的隐藏值.我希望能够做类似的事情
driver.findElement(protractor.By.xpath('/html/body/div/div/a')).mouseover.then(function() {
ptor.findElement(protractor.By.className('name').getText().then(function(result) {
expect(result).toBe('Me');
});
});
Run Code Online (Sandbox Code Playgroud)
当菜单项不可见时,或者我们目前是否受此限制.如果这是不可能的,目前有办法解决这个问题.
单击操作栏中的中间图标时,会出现一个下拉菜单:

我如何制作其中一个?RelativeLayouts?
Eclipse当我在模拟器和手机上遇到强制关闭错误时,我正在使用IDE 编写一个Android应用程序.我只是改变了布局,strings.xml并且我没有在eclipse中显示错误,当我尝试在eclipse模拟器或智能手机上打开应用程序时,它仍然说"强制关闭".这是我的布局,main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ButtonConnect" />
<Button
android:id="@+id/device"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/connect"
android:text="@string/ButtonDevice" />
<ImageView
android:id="@+id/joystick_hulle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/joystickhulle"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="30dp"
android:layout_marginLeft="30dp"
android:src="@drawable/joystick_bg" />
<ImageView
android:id="@+id/joystick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/joystick"
android:layout_alignLeft="@+id/joystick_hulle"
android:layout_alignTop="@+id/joystick_hulle"
android:layout_marginLeft="17dp"
android:layout_marginTop="17dp"
android:src="@drawable/joystick" />
<Button
android:id="@+id/M1P"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/device"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/device"
android:text="@string/Pfeilhoch" />
<Button
android:id="@+id/M2P"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/M1P"
android:layout_alignBottom="@+id/M1P"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/M1P"
android:text="@string/Pfeilhoch" />
<Button
android:id="@+id/M3P"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/M2P"
android:layout_alignBottom="@+id/M2P"
android:layout_marginLeft="25dp"
android:layout_toRightOf="@+id/M2P"
android:text="@string/Pfeilhoch" />
<Button
android:id="@+id/M4P" …Run Code Online (Sandbox Code Playgroud) 我已编写此代码在屏幕上打开surfaceview上的前置摄像头,但是当你点击按钮时我想用前置摄像头录制视频.
这段代码崩溃了.我已经为相机使用了两个不同的变量,但我找不到我的错误:( ..我已经按照谷歌指南.
public class MainActivity extends Activity {
public static final int MEDIA_TYPE_VIDEO = 2;
private Camera mCamera;
private CameraPreview mPreview;
public static final int MEDIA_TYPE_IMAGE = 1;
protected static final String TAG = null;
private MediaRecorder mMediaRecorder;
private Camera mCamerafront;
private boolean isRecording = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Button captureButton = (Button) findViewById(id.button_capture);
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = …Run Code Online (Sandbox Code Playgroud) 我在尝试通过SQL语句将最近的位置返回给用户时遇到问题.为了测试我使用完全相同的坐标,这里是我所拥有的:
SQL:
SELECT `companies`.`customerName` ,
(3959 *
ACOS(
COS(
RADIANS(37.367485) * COS(RADIANS(`locations`.`gps_lat`)) *
COS(
RADIANS(`locations`.`gps_lng`) - RADIANS(-77.399994) +
SIN(RADIANS(37.367485)) * SIN(RADIANS(`locations`.`gps_lat`))
)
)
)
)
AS `distance`
FROM `locations`
JOIN `companies` ON `locations`.`co_id`
HAVING `distance` > 25
ORDER BY distance
LIMIT 0 , 10
Run Code Online (Sandbox Code Playgroud)
结果:
| customerName | distance |
| SOME COMPANY | 1914.41747964854 |
Run Code Online (Sandbox Code Playgroud)
locations 表值:
gps_lat | gps_lng
37.367485 | -77.399994
Run Code Online (Sandbox Code Playgroud)
我使用了谷歌的例子,我检查了几次公式,我似乎无法想出我出错的地方.任何帮助表示赞赏.
编辑:
因为我知道自己在做什么似乎有些困惑:
的>被取代的,得到的结果,1914很明显大于25.
这个应用程序是将用户坐标从Android应用程序传递到我们的Web服务器.纬度和经度将从$_GET值中提取,并从我们的Web服务器MYSQL数据库中的公司进行交叉引用.
上面的语法只是我在Mysql …
我正在使用exifInterface进行照片旋转问题代码如下:面对从相机捕获的图像方向问题.
Bitmap b = BitmapFactory.decodeFile(imagePath);
Run Code Online (Sandbox Code Playgroud)
int width = b.getWidth();
int height = b.getHeight();
int newWidth = 150;
int newHeight = 150;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
// resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
Run Code Online (Sandbox Code Playgroud)
ExifInterface exif = new ExifInterface(imagePath);
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
if (orientation.equals(ExifInterface.ORIENTATION_NORMAL)) {
// Do nothing. The original image is fine. …Run Code Online (Sandbox Code Playgroud) 我有以下TabHost布局:
<?xml version="1.0" encoding="iso-8859-1"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:padding="0dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:background="@drawable/main_app_background"
android:orientation="vertical"
android:padding="0dp" >
<ImageView
android:id="@+id/logo"
android:layout_width="fill_parent"
android:layout_height="@dimen/site_logo_height"
android:layout_margin="0dp"
android:background="@color/tab_subtitle_background"
android:padding="0dp"
android:src="@drawable/barlogo" />
<FrameLayout
android:id="@+id/tab_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:gravity="center"
android:padding="0dp" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_margin="0dp"
android:layout_weight="99"
android:padding="0dp" />
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="7dp"
android:focusableInTouchMode="true"
android:imeOptions="actionNext"
android:tag="done"
android:text="Ok" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:padding="0dp" />
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
问题是,当软键盘出现时,Button和TabWidget都向上移动.
我的目标是将TabWidget保持在底部(软键盘下方),然后让Ok按钮向上移动(在键盘顶部).可能吗?
提前致谢!
android view android-widget android-layout android-softkeyboard