- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我是 Android 开发新手......我正在编写一个应用程序,允许用户输入值,并将它们用于在图表上绘制。最近几天,我一直被一个特定的问题困扰,似乎无法克服。用户将输入 2 个值,然后根据这 3 个值进行计算并将其传递给内部类以在图表上绘制。这些值是 TextView 形式的。我知道大部分代码都可以工作,因为我一直在测试它,并且我很确定该错误与 TextView 值有关。下面是用于计算和绘制图表的代码。
package com.example.ballanimation;
import java.math.BigDecimal;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class calculations extends Activity {
EditText firstVal, secondVal;
TextView resultA, resultB, resultC;
Button button3;
BigDecimal firstNum, secNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.calculations_page);
button3 = (Button) findViewById(R.id.button3);
firstVal = (EditText) findViewById(R.id.editTXT1);
secondVal = (EditText) findViewById(R.id.editTXT2);
resultA = (TextView) findViewById(R.id.result1);
resultB = (TextView) findViewById(R.id.result2);
resultC = (TextView) findViewById(R.id.result3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
firstNum = new BigDecimal(firstVal.getText().toString());
secNum = new BigDecimal(secondVal.getText().toString());
resultA.setText(firstNum.add(secNum).toString());
resultB.setText(firstNum.subtract(secNum).toString());
resultC.setText(firstNum.multiply(secNum).toString());
}
});
}
class TestA1 extends View{
public TestA1(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public void onDraw(Canvas canvas){
super.onDraw(canvas);
String TestA = resultA.getText().toString();
String TestB = resultB.getText().toString();
String TestC = resultC.getText().toString();
int A = Integer.parseInt(TestA);
int B = Integer.parseInt(TestB);
int C = Integer.parseInt(TestC);
Paint red = new Paint();
red.setColor(Color.RED);
red.setStyle(Paint.Style.STROKE);
Paint black = new Paint();
black.setColor(Color.BLACK);
black.setStyle(Paint.Style.STROKE);
canvas.drawCircle(A, B, C, black);
canvas.drawCircle(canvas.getWidth()*1/2, canvas.getHeight()*3/8, canvas.getWidth()*475/1000, black);
canvas.drawCircle(canvas.getWidth()*5/8, canvas.getWidth()*5/8, canvas.getWidth()*349/1000, black);
canvas.drawCircle(canvas.getWidth()*6/8, canvas.getWidth()*5/8, canvas.getWidth()*228/1000, black);
canvas.drawCircle(canvas.getWidth()*7/8, canvas.getWidth()*5/8, canvas.getWidth()*103/1000, black);
canvas.drawLine((canvas.getWidth()-canvas.getWidth()) + 10, (canvas.getHeight()*3)/8, canvas.getWidth() - 10, (canvas.getHeight()*3)/8, black);
float a, b, c, d, e, f, g, h, i, j, k, l;
a = 90; //degrees
b = 90;
c = 90;
d = 50;
e = 90;
f = 134;
g = -90;
h = -90;
i = -90;
j = -50;
k = -90;
l = -134;
RectF arc0 = new RectF();
RectF arc1 = new RectF();
RectF arc2 = new RectF();
RectF arc3 = new RectF();
RectF arc4 = new RectF();
RectF arc5 = new RectF();
/*left The X coordinate of the left side of the rectangle
top The Y coordinate of the top of the rectangle
right The X coordinate of the right side of the rectangle
bottom The Y coordinate of the bottom of the rectangle */
arc0.set(canvas.getWidth()*1/2, canvas.getHeight()*-139/700, canvas.getWidth()*100/69, canvas.getHeight()*3/8);
arc1.set(canvas.getWidth()*-6/112, canvas.getHeight()*-80/100, canvas.getWidth()*195/100, canvas.getHeight()*72/192);
arc2.set(canvas.getWidth()*7/10, canvas.getHeight()*70/700, canvas.getWidth()*125/100, canvas.getHeight()*3/8);
arc3.set(canvas.getWidth()/2, canvas.getHeight()*3/8, canvas.getWidth()*100/69, canvas.getHeight()*91/96);
arc4.set(canvas.getWidth()*-8/112, canvas.getHeight()*3/8, canvas.getWidth()*195/100, canvas.getHeight()*150/100);
arc5.set(canvas.getWidth()*7/10, canvas.getHeight()*3/8, canvas.getWidth()*125/100, canvas.getHeight()*65/100);
/*oval The bounds of oval used to define the shape and size of the arc
startAngle Starting angle (in degrees) where the arc begins
sweepAngle Sweep angle (in degrees) measured clockwise
useCenter If true, include the center of the oval in the arc, and close it if it is being stroked. This will draw a wedge
paint The paint used to draw the arc */
canvas.drawArc(arc0, a, b, false, red);
canvas.drawArc(arc1, c, d, false, red);
canvas.drawArc(arc2, e, f, false, red);
canvas.drawArc(arc3, g, h, false, red);
canvas.drawArc(arc4, i, j, false, red);
canvas.drawArc(arc5, k, l, false, red);
}
}
}
我收到的 logcat 错误是:
01-04 13:08:46.764: E/Trace(918): error opening trace file: No such file or directory (2)
01-04 13:08:47.593: D/dalvikvm(918): GC_FOR_ALLOC freed 59K, 3% free 8053K/8259K, paused 105ms, total 108ms
01-04 13:08:47.604: I/dalvikvm-heap(918): Grow heap (frag case) to 8.305MB for 412064-byte allocation
01-04 13:08:47.703: D/dalvikvm(918): GC_FOR_ALLOC freed 1K, 3% free 8454K/8711K, paused 61ms, total 61ms
01-04 13:08:47.764: D/dalvikvm(918): GC_FOR_ALLOC freed 0K, 3% free 8454K/8711K, paused 57ms, total 57ms
01-04 13:08:47.794: I/dalvikvm-heap(918): Grow heap (frag case) to 9.189MB for 928216-byte allocation
01-04 13:08:47.964: D/dalvikvm(918): GC_CONCURRENT freed 0K, 4% free 9361K/9671K, paused 98ms+6ms, total 168ms
01-04 13:08:47.964: D/dalvikvm(918): WAIT_FOR_CONCURRENT_GC blocked 11ms
01-04 13:08:48.344: I/Choreographer(918): Skipped 36 frames! The application may be doing too much work on its main thread.
01-04 13:08:48.374: D/gralloc_goldfish(918): Emulator without GPU emulation detected.
01-04 13:08:50.025: I/Choreographer(918): Skipped 46 frames! The application may be doing too much work on its main thread.
01-04 13:08:56.844: I/Choreographer(918): Skipped 38 frames! The application may be doing too much work on its main thread.
01-04 13:08:57.514: D/AndroidRuntime(918): Shutting down VM
01-04 13:08:57.514: W/dalvikvm(918): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-04 13:08:57.614: E/AndroidRuntime(918): FATAL EXCEPTION: main
01-04 13:08:57.614: E/AndroidRuntime(918): java.lang.NullPointerException
01-04 13:08:57.614: E/AndroidRuntime(918): at com.example.ballanimation.calculations$TestA1.onDraw(calculations.java:68)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.View.draw(View.java:13458)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.View.draw(View.java:13342)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.View.draw(View.java:13461)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.widget.FrameLayout.draw(FrameLayout.java:467)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.View.draw(View.java:13342)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.View.draw(View.java:13340)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.View.draw(View.java:13461)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.widget.FrameLayout.draw(FrameLayout.java:467)
01-04 13:08:57.614: E/AndroidRuntime(918): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2256)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2151)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.Choreographer.doFrame(Choreographer.java:525)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.os.Handler.handleCallback(Handler.java:615)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.os.Handler.dispatchMessage(Handler.java:92)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.os.Looper.loop(Looper.java:137)
01-04 13:08:57.614: E/AndroidRuntime(918): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-04 13:08:57.614: E/AndroidRuntime(918): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 13:08:57.614: E/AndroidRuntime(918): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 13:08:57.614: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-04 13:08:57.614: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-04 13:08:57.614: E/AndroidRuntime(918): at dalvik.system.NativeStart.main(Native Method)
01-04 13:08:59.854: I/Process(918): Sending signal. PID: 918 SIG: 9
01-04 13:09:13.584: E/Trace(960): error opening trace file: No such file or directory (2)
01-04 13:09:14.364: D/dalvikvm(960): GC_FOR_ALLOC freed 63K, 3% free 8053K/8259K, paused 73ms, total 76ms
01-04 13:09:14.364: I/dalvikvm-heap(960): Grow heap (frag case) to 8.305MB for 412064-byte allocation
01-04 13:09:14.445: D/dalvikvm(960): GC_FOR_ALLOC freed 1K, 3% free 8454K/8711K, paused 42ms, total 42ms
01-04 13:09:14.494: D/dalvikvm(960): GC_FOR_ALLOC freed 0K, 3% free 8454K/8711K, paused 48ms, total 48ms
01-04 13:09:14.514: I/dalvikvm-heap(960): Grow heap (frag case) to 9.189MB for 928216-byte allocation
01-04 13:09:14.684: D/dalvikvm(960): GC_CONCURRENT freed 0K, 4% free 9361K/9671K, paused 80ms+18ms, total 162ms
01-04 13:09:15.024: D/gralloc_goldfish(960): Emulator without GPU emulation detected.
01-04 13:09:16.874: I/Choreographer(960): Skipped 94 frames! The application may be doing too much work on its main thread.
01-04 13:09:20.643: I/Choreographer(960): Skipped 31 frames! The application may be doing too much work on its main thread.
01-04 13:09:32.394: W/ResourceType(960): No package identifier when getting value for resource number 0x00000064
01-04 13:09:32.394: D/AndroidRuntime(960): Shutting down VM
01-04 13:09:32.394: W/dalvikvm(960): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-04 13:09:32.454: E/AndroidRuntime(960): FATAL EXCEPTION: main
01-04 13:09:32.454: E/AndroidRuntime(960): android.content.res.Resources$NotFoundException: String resource ID #0x64
01-04 13:09:32.454: E/AndroidRuntime(960): at android.content.res.Resources.getText(Resources.java:229)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.widget.TextView.setText(TextView.java:3620)
01-04 13:09:32.454: E/AndroidRuntime(960): at com.example.ballanimation.calculations$1.onClick(calculations.java:49)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.view.View.performClick(View.java:4084)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.view.View$PerformClick.run(View.java:16966)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.os.Handler.handleCallback(Handler.java:615)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.os.Handler.dispatchMessage(Handler.java:92)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.os.Looper.loop(Looper.java:137)
01-04 13:09:32.454: E/AndroidRuntime(960): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-04 13:09:32.454: E/AndroidRuntime(960): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 13:09:32.454: E/AndroidRuntime(960): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 13:09:32.454: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-04 13:09:32.454: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-04 13:09:32.454: E/AndroidRuntime(960): at dalvik.system.NativeStart.main(Native Method)
01-04 13:09:34.894: I/Process(960): Sending signal. PID: 960 SIG: 9
如果信息量很大,我很抱歉,但我真的被这个问题困扰了。任何帮助将不胜感激。
问候P
最佳答案
因为 View.getText()
永远不会返回 null
,只返回 String resultA
、 resultB
或 resultC
可以为 null
:
在R.layout内声明了
?R.id.result1
、R.id.result2
、R.id.result3
.calculations_page
关于java - 在类之间传递 TextView 值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14158477/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!