我想在导航抽屉标题内更改TextView的文本.但我得到这个错误:
java.lang.NullPointerException:尝试在空对象引用上调用虚方法'void android.widget.TextView.setText(java.lang.CharSequence)'
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<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" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
nav_header_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/slide_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/tvHeaderIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:src="@android:drawable/sym_def_app_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/tvHeaderName"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
TextView tvHeaderName; …Run Code Online (Sandbox Code Playgroud) 我搜索了所有的互联网网站来修复这个错误,但我不能.我只想用两个按钮创建AlertDialog是和否.
这是我的代码:
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class DialogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
Button btnDialog= (Button) findViewById(R.id.btnDialog);
btnDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialogMessage();
}
});
}
private void showDialogMessage(){
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
// Add the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public …Run Code Online (Sandbox Code Playgroud) 我可以在Activity中使用Parcelable,但我不知道如何在Fragment中使用它.
我有一个FragmentGet在ListFragment ListView中显示所有行的数据库,我想在另一个片段的ListView的详细信息,单击时,我使用Parcelable到片段之间传递数据.
这是我的Test.java:
import android.os.Parcel;
import android.os.Parcelable;
public class Test implements Parcelable {
private int studentNumber;
private String studentName;
private String studentFamily;
public int getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(int studentNumber) {
this.studentNumber = studentNumber;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentFamily() {
return studentFamily;
}
public void setStudentFamily(String studentFamily) {
this.studentFamily = studentFamily;
}
public Test() {
}
public Test(Parcel read) {
studentNumber …Run Code Online (Sandbox Code Playgroud) 我在android studio编码然后会出现这个错误:
无法解析符号'R'
错误:任务':demo:processDebugResources'的执行失败.com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'命令'D:\ Android Development\sdk\android-sdk\build-tools\22.0.1\aapt.exe' '完成时非零退出值1
这是我的Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "br.liveo.ndrawer"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile project(':library')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
}
Run Code Online (Sandbox Code Playgroud)
我使用Android Studio V 1.0,更新所有API 22和API 21以及SDK Manager的工具和附加功能.
这个选项不起作用:
文件/无效兑现/重新启动
建立/重建项目
建立/清洁项目
我该怎么知道?
TNX
我打开一个网页,Process.Start("Chrome.exe", "https://www.google.com/");
然后我想将一个 chrome 标签 HTML 页面(谷歌 HTML 代码)保存到 C# 中的一个字符串中。我该怎么做?
我需要指定打开的 url HTML 代码并将其保存为字符串。因为该网页包含的内容每分钟都在变化。