我有一个自定义视图,使用这些构造函数扩展LinearLayout:
public class CustomView extends LinearLayout {
public CustomView(Context context) {
this(context, null);
}
public CustomView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.customViewStyle);
}
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
/* set custom attributes with TypedArray */
}
/* other methods */
}
Run Code Online (Sandbox Code Playgroud)
在我的/res/values/attrs.xml中:
<attr name="customViewStyle" format="reference" />
<declare-styleable name="CustomeView">
<attr name="value" format="integer" />
<attr name="android:imeOptions" />
<attr name="android:imeActionId" />
<attr name="android:imeActionLabel" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
在我的/res/values/styles.xml中:
<style name="AppTheme" parent="@android:style/Theme.Black">
<item name="android:windowBackground">@drawable/bg_dark_fiber</item>
<item name="customViewStyle">@style/CustomViewStyle</item>
</style>
<style name="CustomViewStyle"> …Run Code Online (Sandbox Code Playgroud) android custom-controls nosuchmethoderror android-linearlayout inflate-exception
我正在创建一个应用程序,当用户选择检查时,将调用第二个活动.但是,当调用第二个活动时,我的应用程序崩溃并且日志cat在我的paycheckactivity oncreate方法上显示错误.
第一项活动
public class TableListActivity extends Activity {
private ListView mListView;
private TableListAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_list);
mListView = (ListView)findViewById(R.id.listView);
mAdapter = new TableListAdapter(this, DataStore.CHECKS);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intent = new Intent (TableListActivity.this, PayCheckActivity.class);
intent.putExtra(PayCheckActivity.Extra_check, arg2);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.table_list, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = …Run Code Online (Sandbox Code Playgroud) 我有一个Android Studio项目在Android版本Lollipop的设备上正常工作,但是在尝试使用Android构建版本Kitkat的设备上运行它时会抛出异常.这是我的项目的build.gradle文件:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/org.apache.commons.io.jar')
compile files('libs/commons-codec-1.10.jar')
compile('com.twitter.sdk.android:twitter:1.6.0@aar') {
transitive = true;
}
compile files('libs/pinit-sdk-1.0.jar')
compile project(':bounceScroller')
compile 'com.ogaclejapan.smarttablayout:library:1.2.1@aar'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.android.support:appcompat-v7:21.2.0'
compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
compile 'com.nineoldandroids:library:2.4.+'
compile 'com.esri.arcgis.android:arcgis-android:10.2.6-2'
compile 'com.github.clans:fab:1.5.3'
compile 'com.github.pedrovgs:draggablepanel:1.8'
compile 'com.android.support:support-v4:21.2.0'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.2.1@aar'
compile 'com.github.bumptech.glide:glide:3.6.0'
compile project(':rangeseekbar')
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile project(':blurry')
compile 'com.google.android.gms:play-services:7.8.0'
} …Run Code Online (Sandbox Code Playgroud) 错误信息:
android.view.InflateException:二进制XML文件行#16:二进制XML文件行#16:在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)错误膨胀类android.support.design.widget.NavigationView
xml文件:
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
Run Code Online (Sandbox Code Playgroud)
的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "edu.zhanglrose_hulman.bigbelly"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.gms:play-services:9.2.0'
}
Run Code Online (Sandbox Code Playgroud)
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个自定义编辑文本,并在这里陷入困境......
请参阅下面的代码
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public static class MyEditText1 extends EditText{
Paint mPaint;
public MyEditText1(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyEditText1(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint=new Paint();
mPaint.setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas c){
super.onDraw(c);
int height=getHeight();
int width=getWidth();
int linespace=10;
int count=height/linespace;
for(int i=0;i<count;i++){
c.drawLine(0, i*linespace, width, i*linespace, mPaint); …Run Code Online (Sandbox Code Playgroud) 在调用Asynctask内部之后,仅在向父RelativeLayout添加背景图像后出现多个错误(此错误仅在使用模拟器时出现,但在与实际设备一起使用时,堆栈跟踪未显示任何内容或正常):
public class UserAuthTask extends AsyncTask<String, Void, String> {
private boolean success = false;
@Override
protected String doInBackground(String... path) {
// TODO: attempt authentication against a network service.
try {
// Simulate network access.
Thread.sleep(2000);
} catch (InterruptedException e) {
return null;
}
Log.d(Constant.TAG_AUTH, path[0]);
String apiRequestReturn = WebServiceUtil.getRequest(path[0]);
if (apiRequestReturn.equals("")) {
Log.d(Constant.TAG_AUTH, "WebService request is null");
return null;
} else {
Log.d(Constant.TAG_AUTH, "WebService request has data");
return apiRequestReturn;
}
}
@Override
protected void onPostExecute(String result) {
userAuthTask = null; …Run Code Online (Sandbox Code Playgroud) android out-of-memory invocationtargetexception runtimeexception inflate-exception
我尝试在我的 android studio 中做一个绘图应用程序,但是当我尝试在我的手机或模拟器上运行它时。该应用程序突然停止。这是我在布局上的 content_main 活动 xml 文件的副本。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFCCCCCC"
android:orientation="vertical"
tools:context=".MainActivity">
<com.example.chadymaebarinan.drawingview
android:id="@+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/new_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/start_new"
android:src="@drawable/new_pic" />
<ImageButton
android:id="@+id/draw_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/brush"
android:src="@drawable/brush" />
<ImageButton
android:id="@+id/erase_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/erase"
android:src="@drawable/eraser" />
<ImageButton
android:id="@+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/save"
android:src="@drawable/save" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="@+id/paint_colors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF660000" …Run Code Online (Sandbox Code Playgroud) 这是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/filebinder" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="14"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="30 July"
android:textColor="#03a9f4"
android:textSize="32sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我在我的Android监视器中得到这个
07-01 18:32:04.693 10005-10005/com.mindefy.kidster E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
07-01 18:32:12.293 10005-10005/com.mindefy.kidster E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mindefy.kidster/com.mindefy.kidster.DiaryEntry.diaryEntryTeacherActivity}: android.view.InflateException: Binary XML file line #9: …Run Code Online (Sandbox Code Playgroud) 当我运行Mainactivity我收到错误和content_main.xml显示错误(错误膨胀class com.algolia.instantsearch.ui.views.Hits).我无法解决它.我也改变了风格.请帮我.
10-29 16:26:35.405 20712-20712/com.google.tho.oe E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
10-29 16:26:35.405 20712-20712/com.google.tho.oe W/dalvikvm: VFY: unable to resolve instanceof 354 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
10-29 16:26:35.415 20712-20712/com.google.tho.oe D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
10-29 16:26:36.055 20712-20712/com.google.tho.oe D/dalvikvm: GC_FOR_ALLOC freed 1340K, 26% free 11327K/15299K, paused 115ms, total 148ms
10-29 16:26:36.655 20712-20712/com.google.tho.oe I/dalvikvm: Could not find method org.greenrobot.eventbus.EventBus.getDefault, referenced from method com.algolia.instantsearch.ui.views.Hits.<init>
10-29 16:26:36.665 20712-20712/com.google.tho.oe W/dalvikvm: VFY: unable to resolve static …Run Code Online (Sandbox Code Playgroud) 我已经实现了一个扩展视图的新ImageLoaderView,如果我以编程方式设置xml,则代码可以正常工作.但由于这似乎很难,我试图让它在我的res布局文件夹中的xml工作,但我收到一个错误.以下是我的代码.
LoaderImageView:
package com.anon.android.test;
import java.io.IOException;
import java.net.MalformedURLException;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
/**
* Free for anyone to use, just say thanks and share :-)
* @author Blundell
*
*/
public class LoaderImageView extends LinearLayout{
private static final int COMPLETE = 0;
private static final int FAILED = 1;
private Context mContext;
private Drawable mDrawable;
private ProgressBar mSpinner;
private ImageView mImage;
/**
* This …Run Code Online (Sandbox Code Playgroud)