我正在开发一款安卓游戏,我一直坚持这个问题 这是次要活动,当我点击带我进入第二个活动的按钮时,它显示了一些错误,我试图通过我自己的搜索和实验来解决这个问题,但是它没有工作<登记/> 这是我的活动:
package game.esolindo.com.gametest;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MoneyActivity extends ActionBarActivity {
private TextView txtMoney;
private Button btnWork;
private Button btnBuyClothes;
int workMoney = 15;
int buyClothesMoney = 20;
int currentMoney;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_money);
txtMoney = (TextView)findViewById(R.id.txtMoney);
btnWork = (Button)findViewById(R.id.btnWork);
btnWork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentMoney = currentMoney + workMoney;
txtMoney.setText(String.valueOf(currentMoney));
}
});
btnBuyClothes = (Button)findViewById(R.id.btnBuyClothes);
btnBuyClothes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentMoney = currentMoney - buyClothesMoney;
txtMoney.setText(String.valueOf(currentMoney));
}
});
txtMoney.setText(currentMoney);
}
}
这是我的xml文件:
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="game.esolindo.com.gametest.MoneyActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Money"
android:id="@+id/txtMoneyText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0"
android:textSize="50sp"
android:id="@+id/txtMoney"
android:layout_below="@+id/txtMoneyText"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work"
android:id="@+id/btnWork"
android:layout_marginTop="20dp"
android:layout_below="@+id/txtMoney"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buy Clothes"
android:id="@+id/btnBuyClothes"
android:layout_below="@+id/btnWork"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
这是我收到的错误消息:
01-14 04:00:15.927 22640-22640/game.esolindo.com.gametest E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: game.esolindo.com.gametest, PID: 22640
java.lang.RuntimeException: Unable to start activity ComponentInfo{game.esolindo.com.gametest/game.esolindo.com.gametest.MoneyActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText(Resources.java:244)
at android.widget.TextView.setText(TextView.java:3888)
at game.esolindo.com.gametest.MoneyActivity.onCreate(MoneyActivity.java:46)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
请帮我解决这个问题 提前致谢
答案 0 :(得分:3)
setText
是一个int,因此String.valueOf(currentMoney)
将查找资源。请使用def saveUploadedInventory(self, inventory_file,user_id):
print "Inventory File"
with open('uploaded_inventory_sheet.csv','wb+') as destination:
for chunk in inventory_file.chunks():
destination.write(chunk)
print "Inventory Saved."
f = open('uploaded_inventory_sheet.csv','rb')
self.cur.copy_from(f, 'fk_payment_temp', sep=',', columns=('settlement_ref_no', 'order_type', 'fulfilment_type', 'seller_sku',
'wsn', 'order_id', 'order_item_id', 'order_date', 'dispatch_date', 'delivery_date',
'cancellation_date', 'settlement_date', 'order_status', 'quantity', 'order_item_value',
'sale_transaction_amount', 'discount_transaction_amount', 'refund',
'protection_fund', 'total_marketplace_fee', 'service_tax', 'swach_bharat_cess',
'settlement_value', 'commission_rate', 'commission', 'payment_rate',
'payment_fee', 'fee_discount', 'cancellation_fee', 'fixed_fee', 'emi_fee',
'total_weight', 'weight_type', 'shipping_fee', 'reverse_shipping_fee',
'shipping_zone', 'token_of_apology', 'pick_and_pack_fee', 'storage_fee',
'removal_fee', 'invoice_id', 'invoice_date', 'invoice_amount', 'sub_category',
'total_offer_amount', 'my_offer_share', 'flipkart_offer_share'))