gpt4 book ai didi

android - 获取资源编号 0x00000000 错误的值时没有包标识符

转载 作者:行者123 更新时间:2023-11-29 17:23:28 25 4
gpt4 key购买 nike

我创建了一个 fragment ,用户可以在其中编辑他们的信息,但是每当我在 android studio 中运行该应用程序时,它总是给我这个错误:在获取资源编号 0x00000000 的值时没有包标识符。我也无法从抽屉导航中打开此网页。

package com.example.redir.wealthtrack;


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.redir.wealthtrack.db.InfoDataSource;
import com.example.redir.wealthtrack.db.LimitDataSource;
import com.example.redir.wealthtrack.model.Info;
import com.example.redir.wealthtrack.model.Limit;


/**
* A simple {@link Fragment} subclass.
*/
public class infoFragment extends Fragment {

public InfoDataSource infoDataSource;
String textInEditText;
String textInEditText2;
String textInEditText3;


public infoFragment() {
// Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

((MainActivity) getActivity()).setActionBarTitle("User Target");


infoDataSource = new InfoDataSource(getActivity().getApplicationContext());
infoDataSource.open();

// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_userinfo, container, false);
final EditText editText = (EditText) view.findViewById(R.id.editText);
final EditText editText2 = (EditText) view.findViewById(R.id.editText2);
final EditText editText3 = (EditText) view.findViewById(R.id.editText3);
editText.setText(infoDataSource.getFirst().getName());
editText2.setText((int) infoDataSource.getFirst().getIncome());
editText3.setText((int) infoDataSource.getFirst().getGoal());

Button AddButton = (Button) view.findViewById(R.id.AddButton);
AddButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder a_builder = new AlertDialog.Builder(getActivity());
a_builder.setMessage("Confirm?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Info newInfo = new Info ();
newInfo.setName(editText.getText().toString());
newInfo.setIncome(Double.parseDouble(editText2.getText().toString()));
newInfo.setGoal(Double.parseDouble(editText3.getText().toString()));
createInfo(newInfo);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = a_builder.create();
alert.setTitle(Html.fromHtml("<font color='#08ae9e'>Confirmation</font>"));
alert.show();
}
});

Button EditButton = (Button) view.findViewById(R.id.EditButton);
EditButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder a_builder = new AlertDialog.Builder(getActivity());
a_builder.setMessage("Are you sure you want to edit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Info newInfo = new Info();
newInfo.setId(1);
newInfo.setName(editText.getText().toString());
newInfo.setIncome(Double.parseDouble(editText2.getText().toString()));
newInfo.setGoal(Double.parseDouble(editText3.getText().toString()));
updateInfo(newInfo);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = a_builder.create();
alert.setTitle(Html.fromHtml("<font color='#08ae9e'>Confirmation</font>"));
alert.show();

}
});

textInEditText = editText.getText().toString();
textInEditText2 = editText2.getText().toString();
textInEditText3 = editText3.getText().toString();
if(textInEditText.matches("")){
EditButton.setVisibility(View.INVISIBLE);
} else if(!textInEditText.matches("")){
AddButton.setVisibility(View.INVISIBLE);
}
if(textInEditText2.matches("")){
EditButton.setVisibility(View.INVISIBLE);
} else if(!textInEditText2.matches("")){
AddButton.setVisibility(View.INVISIBLE);
}
if(textInEditText3.matches("")){
EditButton.setVisibility(View.INVISIBLE);
} else if(!textInEditText3.matches("")){
AddButton.setVisibility(View.INVISIBLE);
}
return view;

}

public static void showToast(Context context, String text) {
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
}

private void createInfo (Info info) {
infoDataSource.createInfo(info);
showToast(getActivity().getApplicationContext(), "Target added");
}

private void updateInfo (Info info) {
infoDataSource.updateInfo(info);
showToast(getActivity().getApplicationContext(), "Target updated");
}



THE DATA


package com.example.redir.wealthtrack.db;


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.example.redir.wealthtrack.model.Info;
import com.example.redir.wealthtrack.model.Limit;

import java.net.URI;


/**
* Created by redir on 24/2/2016.
*/
public class InfoDataSource {
public static final String LOGTAG="WEALTHTRACK";

SQLiteOpenHelper dbhelper;
SQLiteDatabase database;

//Create some Static Variable for the Column Names
private static final String[] allColumns = {
WealthDBOpenHelper.INFO_ID,
WealthDBOpenHelper.COLUMN_NAME,
WealthDBOpenHelper.COLUMN_INCOME,
WealthDBOpenHelper.COLUMN_GOAL
};

public InfoDataSource(Context context) {
dbhelper = new WealthDBOpenHelper(context);
}

//open the DB to edit
public void open() {
Log.i(LOGTAG, "Database opened");
database = dbhelper.getWritableDatabase();
}

//Closing the DB
public void close() {
Log.i(LOGTAG, "Database closed");
dbhelper.close();
}

public Info createInfo (Info info) {
ContentValues values = new ContentValues();
values.put(WealthDBOpenHelper.COLUMN_NAME, info.getName());
values.put(WealthDBOpenHelper.COLUMN_INCOME, info.getIncome());
values.put(WealthDBOpenHelper.COLUMN_GOAL, info.getGoal());
long insertid = database.insert(WealthDBOpenHelper.TABLE_INFO, null, values);
info.setId(insertid);
return info;
}
public boolean updateInfo (Info info) {
ContentValues values = new ContentValues();
values.put(WealthDBOpenHelper.COLUMN_NAME, info.getName());
values.put(WealthDBOpenHelper.COLUMN_INCOME, info.getIncome());
values.put(WealthDBOpenHelper.COLUMN_GOAL, info.getGoal());
String where = WealthDBOpenHelper.INFO_ID + "=" + info.getId();
int result = database.update(WealthDBOpenHelper.TABLE_INFO, values, where, null);
return (result ==1);
}


public Info getFirst() {
Info info = new Info();
Cursor cursor = database.query(WealthDBOpenHelper.TABLE_INFO, allColumns,
null, null, null, null, null);
if (cursor.moveToFirst()){
info.setId(cursor.getLong(cursor.getColumnIndex(WealthDBOpenHelper.INFO_ID)));
info.setName(cursor.getString(cursor.getColumnIndex(WealthDBOpenHelper.COLUMN_NAME)));
info.setIncome(Double.parseDouble(cursor.getString(cursor.getColumnIndex(WealthDBOpenHelper.COLUMN_INCOME))));
info.setGoal(Double.parseDouble(cursor.getString(cursor.getColumnIndex(WealthDBOpenHelper.COLUMN_GOAL))));
}
return info;
}

}


THE LAYOUT

<RelativeLayout 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"
tools:context=".infoFragment">

<!-- TODO: Update blank fragment layout -->


<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="@+id/editText"
android:padding="8dp"
android:hint="Name"
android:layout_marginTop="93dp"
android:textColorHint="@color/textcolor"
android:textColor="@color/textcolor"
android:background="#08ae9e"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/editText2"
android:hint="Monthly income"
android:padding="8dp"
android:textColorHint="@color/textcolor"
android:textColor="@color/textcolor"
android:background="#08ae9e"
android:layout_below="@+id/editText"
android:layout_alignStart="@+id/editText"
android:layout_marginTop="20dp" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="@+id/editText3"
android:padding="8dp"
android:hint="Saving goal"
android:textColorHint="@color/textcolor"
android:textColor="@color/textcolor"
android:background="#08ae9e"
android:layout_below="@+id/editText2"
android:layout_alignStart="@+id/editText2"
android:layout_marginTop="20dp" />

<Button
android:layout_width="200dp"
android:layout_height="45dp"
android:text="Add"
android:id="@+id/AddButton"
android:textColor="#ffffff"
android:background="#08ae9e"
android:padding="8dp"
android:clickable="true"
android:layout_below="@+id/editText3"
android:layout_alignEnd="@+id/editText3"
android:layout_marginTop="45dp"
android:layout_alignStart="@+id/editText3" />

<Button
android:layout_width="200dp"
android:layout_height="45dp"
android:text="Edit"
android:id="@+id/EditButton"
android:textColor="#ffffff"
android:background="#08ae9e"
android:padding="8dp"
android:clickable="true"
android:layout_marginTop="20dp"
android:layout_below="@+id/AddButton"
android:layout_alignStart="@+id/AddButton"
android:layout_alignEnd="@+id/AddButton" />

</RelativeLayout>

最佳答案

        editText2.setText((int) infoDataSource.getFirst().getIncome());
editText3.setText((int) infoDataSource.getFirst().getGoal());

您不小心使用了 setText(int resId) 的重载版本而不是 setText(String text) 并且在这种情况下找不到标识符为 0 的字符串资源.

关于android - 获取资源编号 0x00000000 错误的值时没有包标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35655500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com